Plugin Directory

Changeset 2753758


Ignore:
Timestamp:
07/08/2022 01:12:20 PM (4 years ago)
Author:
datacake
Message:

Building 1.2.9

Location:
datacake-core
Files:
1 deleted
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • datacake-core/tags/1.2.9/README.md

    r2708122 r2753758  
    88* This is a Wordpress plugin, for Datacake clients and other customers who would like the functionalities
    99Based on the City you can create page redirects to show the correct page
    10 - shortcodes:
    11 dk_city_cobertura
     10 shortcodes: <--- Vai criar o formulario de cobertura
     11dk_city_cobertura
     12    Atributes of the shortcode:
     13    'success' => '😊🎉✔<br>Temos cobertura em sua cidade',
     14    'error' => 'Infelizmente sua cidade não tem cobertura ainda.<br>Qualquer dúvida entre em contato.',
     15    'assine_url' => '/assine'
    1216dk_city_list <--- This will create a list of all the cities on the system
     17    Atributes of the shortcode:
     18    'list_class' => 'g-cols via_flex valign_top type_default',
     19    'list_item_class' => 'vc_col-sm-{{col}} wpb_column vc_column_container',
     20    'col' => 3,
     21    'include_neighborhood' => false,
    1322dk_city_select <--- This will create a select with a button to save the cookie
     23    Atributes of the shortcode:
     24    'display_field' => 'name',
     25    'group_class' => 'form-group',
     26    'group_id' => 'choosecity-formgroup',
     27    'name' => 'in-cities',
     28    'select-class' => 'form-control',
     29    'btn_id' => 'chooseCitySubmit',
     30    'btn_class' => 'btn btn-outline-primary text-white',
     31    'btn_text' => 'Continuar',
     32    'ignore_neighborhood' => false,
     33    'auto_select' => false
    1434dk_city_pin <--- This will create a pin with information of the selected city
     35    Atributes of the shortcode
     36    'class' => 'pin-city',
     37    'class-marker' => 'fa fa-map-marker',
     38    'class-dropdown' => 'fa fa-chevron-down'
    1539- widgets:
    1640City SEO, this will replicate a text changing the city in the text for SEO purposes
    17 
    18 * Version: V1.2.8
     41* Version: V1.2.9
    1942
    2043
  • datacake-core/tags/1.2.9/README.txt

    r2708122 r2753758  
    66Tested up to: 5.9.2
    77Requires PHP: 7.2
    8 Stable tag: 1.2.8
    9 Last Tag: 1.2.7
     8Stable tag: 1.2.9
     9Last Tag: 1.2.8
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141    'btn_text' => 'Continuar',
    4242    'ignore_neighborhood' => false,
     43    'auto_select' => false
    4344dk_city_pin <--- This will create a pin with information of the selected city
    4445    Atributes of the shortcode
  • datacake-core/tags/1.2.9/datacake_core.php

    r2708122 r2753758  
    1616 * Plugin URI:        http://www.datacake.com.br
    1717 * Description:       Plugin Datacake para linkar com as Funcionalidade do Data ISP/ISP OG - Redirecionar cidade baseada no cookie
    18  * Version:           1.2.8
     18 * Version:           1.2.9
    1919 * Author:            Paulo Peres Jr
    2020 * Author URI:        https://github.com/PauloPeres
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define( 'DATACAKE_CORE_VERSION', '1.2.8' );
     38define( 'DATACAKE_CORE_VERSION', '1.2.9' );
    3939
    4040require_once __DIR__ . '/vendor/autoload.php';
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/AbstractApiView.php

    r2698991 r2753758  
    88    public $api;
    99    public $extraActions = [];
     10
     11    public function create_or_get_term_id($name,$taxonomy,$parent_id=0,$slug=null){
     12        $term = term_exists( $name, $taxonomy );
     13        if(!$slug){
     14            $slug = "dk_".sanitize_title($name);
     15        }
     16        $data = [
     17            'description' => $name,
     18            'slug' => $slug,
     19            'parent' => $parent_id,
     20        ];
     21       
     22        if($term){
     23            $term = wp_update_term($term['term_id'], $taxonomy ,$data);
     24        }else{
     25            $term = wp_insert_term($name, $taxonomy ,$data);
     26        }
     27        return $term['term_id'];
     28    }
     29    public function get_current_terms($id,$taxonomy, $skip_dk = true){
     30        if($id){
     31            $cur_terms = get_the_terms($id, $taxonomy);
     32            if($cur_terms){
     33                $ids = [];
     34                foreach ($cur_terms as $key => $term) {
     35                    if(!str_contains($term->slug, "dk_")){
     36                        $ids[] = $term->term_id;
     37                    }
     38                   
     39                }
     40                return $ids;
     41            }
     42        }
     43        return [];
     44    }
    1045
    1146    function register_actions($loader){
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ChannelApiView.php

    r2698991 r2753758  
    8282                        }
    8383                    }
    84                    
    85                     $tags = $this->get_terms_tags_ids($doc->relationship('types'));
     84                    $post_id = $post ? $post->ID : null;
     85                    $tags = $this->get_terms_tags_ids($doc->relationship('types'),$post_id);
    8686                    $cats = array_merge(
    87                         $this->get_category_ids($doc->relationship('groups')),
    88                         $this->get_plan_category($doc->relationship('products'))
     87                        $this->get_category_ids($doc->relationship('groups'),$post_id),
     88                        $this->get_plan_category($doc->relationship('products'),$post_id)
    8989                    );
    9090                   
     
    149149    }
    150150
    151     private function get_terms_tags_ids($documents){
    152        
    153         $ids = [];
     151   
     152   
     153    private function get_terms_tags_ids($documents,$id){
     154       
     155        $ids = $this->get_current_terms($id,'isp_canais_tag');
     156       
    154157        foreach ($documents->resources() as $key => $doc) {
    155             $term = term_exists( $doc->attribute('name'), 'isp_canais_tag' );
    156             if($term){
    157               $ids[] = $doc->attribute('name');
     158            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_tag');
     159            if($term_id){
     160              $ids[] = $term_id;
    158161            }
    159162        }
     
    161164        return $ids;
    162165    }
    163     private function get_category_ids($documents){
    164         $parent_term = term_exists( 'Grupos','isp_canais_category');
    165         $ids = [];
    166         $ids[] = $parent_term['term_id'];
     166    private function get_category_ids($documents,$id){
     167        $parent_id = $this->create_or_get_term_id( 'Grupos','isp_canais_category');
     168       
     169        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     170        $ids = $this->get_current_terms($id,'isp_canais_category');
     171        //$ids = [];
     172        $ids[] = $parent_id;
    167173        foreach ($documents->resources() as $key => $doc) {
    168             $term = term_exists( $doc->attribute('name'), 'isp_canais_category' );
    169             if($term){
    170                 $ids[] = $term['term_id'];
     174            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_category',$parent_id);
     175           
     176            if($term_id){
     177                $ids[] = $term_id;
    171178            }
    172179        }
    173180        return $ids;
    174181    }
    175     private function create_or_get_parent_product_category(){
    176         $term = term_exists( 'Planos','isp_canais_category');
    177         if($term){
    178             return $term['term_id'];
    179         }
    180         $data = [
    181             'description' => 'Planos',
    182             'slug' => 'planos',
    183             'parent' => null,
    184         ];
    185        
    186         $term_id = wp_insert_term('Planos','isp_canais_category',$data);
    187         return $term_id;
    188        
    189     }
    190     private function create_or_get_term_id($doc,$parent_id){
    191         $term = term_exists( $doc->attribute('name'), 'isp_canais_category' );
    192         $data = [
    193             'description' => $doc->attribute('name'),
    194             'slug' => $doc->attribute('sku'),
    195             'parent' => $parent_id,
    196         ];
    197        
    198         if($term){
    199             $term_id = wp_update_term($term['term_id'], 'isp_canais_category' ,$data);
    200         }else{
    201             $term_id = wp_insert_term($doc->attribute('name'), 'isp_canais_category' ,$data);
    202         }
    203         return $term['term_id'];
    204     }
    205     private function get_plan_category($plans){
    206         $parent_id = $this->create_or_get_parent_product_category();
    207         $ids = [];
     182   
     183   
     184    private function get_plan_category($plans,$id){
     185        $parent_id = $this->create_or_get_term_id( 'Planos','isp_canais_category');
     186        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     187        $ids = $this->get_current_terms($id,'isp_canais_category');
     188        //$ids = [];
    208189        $ids[] = $parent_id;
    209190        foreach ($plans->resources() as $key => $doc) {
    210             $term_id = $this->create_or_get_term_id($doc,$parent_id);
     191            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_category',$parent_id,"dk_".$doc->attribute('sku'));
    211192            if($term_id){
    212193                $ids[] = $term_id;
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ChannelGroupApiView.php

    r2698991 r2753758  
    1414        ];
    1515    }
    16     private function create_or_get_parent_group_category(){
    17         $term = term_exists( 'Grupos', $this->taxonomy);
    18         if($term){
    19             return $term['term_id'];
    20         }
    21         $data = [
    22             'description' => 'Grupos',
    23             'slug' => 'grupos',
    24             'parent' => null,
    25         ];
    26        
    27         $term_id = wp_insert_term('Grupos', $this->taxonomy, $data);
    28         return $term_id;
    29        
    30     }
     16   
    3117    function sync(){
    3218       
     
    5137        if($response->isSuccessful()){
    5238            if($response->hasDocument()){
    53                 $parent_id = $this->create_or_get_parent_group_category();
     39                $parent_id = $this->create_or_get_term_id( 'Grupos',$this->taxonomy );
     40               
    5441                foreach ($response->document()->primaryResources() as $key => $doc) {
    55                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    56                     $data = [
    57                         'description' => $doc->attribute('name'),
    58                         'slug' => $doc->attribute('name'),
    59                         'parent' => $parent_id,
    60                     ];
    61                    
    62                     if($term){
    63                         $term_id = wp_update_term($term['term_id'],$this->taxonomy,$data);
    64                     }else{
    65                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    66                     }
     42                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy,$parent_id );
    6743                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    68                    
    6944                }
    7045            }else{
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ChannelTypeApiView.php

    r2698991 r2753758  
    3636            if($response->hasDocument()){
    3737                foreach ($response->document()->primaryResources() as $key => $doc) {
    38                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    39 
    40                     $data = [
    41                         'slug' => $doc->id(),
    42                         'parent' => null,
    43                     ];
    44                    
    45                     if($term){
    46                         $term_id = wp_update_term($term['term_id'], $this->taxonomy, $data);
    47                     }else{
    48                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    49                     }
     38                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy );
    5039                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5140                }
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/CityApiView.php

    r2698991 r2753758  
    44use Datacake\Core\Admin\ApiViews\AbstractApiView;
    55use Datacake\Core\Wda\CityApi;
     6use Datacake\Core\Models\IspCity;
    67
    78class CityApiView extends AbstractApiView {
     
    910        $this->path = "isp_city_view";
    1011        $this->api = new CityApi();
     12        $this->extraActions = [
     13            "sync"
     14        ];
     15        $this->cityApi = new CityApi();
     16    }
     17    public function sync(){
     18       
     19        $message = [
     20            "status"=>"error",
     21            "mensagem" => "starting"
     22        ];
     23        $q = $this->api;
     24        $page = ["number" => 1, "size" => 15];
     25        if(isset($_POST['page'])){
     26            $page["number"] = sanitize_key($_POST['page']);
     27        }
     28       
     29        $q = $q->setJsonApiPage($page);
     30        $q = $q->setJsonApiFields([
     31            'created','updated','name','short_name',
     32                'id','code','lat','long',
     33                'redirect_url','is_neighborhood','neighborhood_name','products','products.id'
     34        ]);
     35        $q = $q->setJsonApiInclude([
     36            'products'
     37        ]);
     38       
     39        //'product_type',
     40        //'addons'
     41        //'options'
     42        //'categories'
     43        //'inventory'
     44        //'tags',
     45        $response = $q->list();
     46       
     47        if($response->isSuccessful()){
     48            if($response->hasDocument()){
     49
     50                foreach ($response->document()->primaryResources() as $key => $doc) {
     51                    $entity = IspCity::where('remote_id',$doc->id())->first();
     52                   
     53                    $data = [
     54                        'name'=>$doc->attribute('name'),
     55                        'short_name'=>$doc->attribute('short_name'),
     56                        'code'=>$doc->attribute('code')?$doc->attribute('code'):$doc->attribute('name'),
     57                        'lat'=>$doc->attribute('lat'),
     58                        'long'=>$doc->attribute('long'),
     59                        'remote_id'=>$doc->id(),
     60                        'redirect_url'=>$doc->attribute('redirect_url'),
     61                        'is_neighborhood'=>$doc->attribute('is_neighborhood'),
     62                        'neighborhood_name'=>$doc->attribute('neighborhood_name'),
     63                    ];
     64                    if($entity){
     65                        $entity->update($data);
     66                    }else{
     67                        $entity = new IspCity();
     68                        $entity->create($data);
     69                    }
     70                    $this->addCityCategoryToProducts($doc->relationship('products'),$doc);
     71                   
     72                   
     73                }
     74               
     75               
     76               
     77            }else{
     78                $message = [
     79                    "status"=>"success",
     80                    "mensagem" => "Sem Cidades"
     81                ];   
     82            }
     83        }else{
     84            // TODO GET ERROR FROM API
     85            $message = [
     86                "status"=>"error",
     87                "mensagem" => "Error from API"
     88            ];
     89        }
     90        $meta = $response->document()->meta();
     91        if($meta['pagination']['page'] < $meta['pagination']['pages']){
     92            $message = [
     93                "status"=>"success",
     94                "mensagem" => "Sincronização de cidades pagina:".$meta['pagination']['page']." de ".$meta['pagination']['pages']." concluida",
     95                "next_page" => $meta['pagination']['page'] + 1,
     96                "pagination" => $meta['pagination']
     97            ];
     98        } else {
     99            $message = [
     100                "status"=>"success",
     101                "mensagem" => "Sincronização de cidades concluida",
     102                "next_page" => null
     103            ];
     104        }
     105
     106        if($message['status'] == "error"){
     107            return wp_send_json_error($message);
     108        }
     109        return wp_send_json_success($message);
     110       
    11111    }
    12112
     113    function getPost($id){
     114        $posts = query_posts(
     115            array(
     116                'post_per_page' => 1,
     117                'post_type' => "isp_planos",
     118                'meta_query' => array(
     119                array(
     120                  'key' => 'isp_remote_id',
     121                  'value' => $id,
     122                )
     123              ),
     124            )
     125        );
     126        $post = null;
     127       
     128        if($posts && count($posts) >= 1 ){
     129            $post = $posts[0];
     130        }
     131        return $post;
     132    }
     133
     134    function addCityCategoryToProducts($documents,$city){
     135        $parent_id = $this->create_or_get_term_id( 'Cidades','isp_planos_category');
     136        foreach ($documents->resources() as $key => $doc) {
     137            $post = $this->getPost($doc->id());
     138            $ids = $this->get_current_terms($post->ID,'isp_planos_category');
     139            $ids[] = $parent_id;
     140            $term_id = $this->create_or_get_term_id( $city->attribute('name'), 'isp_planos_category' ,$parent_id);
     141            $ids[] = $term_id;
     142            wp_set_object_terms($post->ID,$ids,'isp_planos_category',true);
     143           
     144           
     145        }
     146       
     147    }
    13148}   
    14149
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ProductApiView.php

    r2698991 r2753758  
    118118                        }
    119119                    }
    120                     $tags = $this->get_terms_tags_ids($doc->relationship('tags'));
    121                     $cats = $this->get_category_ids($doc->relationship('categories'));
     120                    $post_id = $post ? $post->ID : null;
     121                    $tags = $this->get_terms_tags_ids($doc->relationship('tags'),$post_id);
     122                    $cats = $this->get_category_ids($doc->relationship('categories'),$post_id);
     123                    /*
     124
     125                    $cats = array_merge(
     126                        $this->get_category_ids($doc->relationship('categories'),$post_id),
     127                        $this->get_cidade_category($doc->relationship('products'),$post_id)
     128                    );
     129                    */
     130
    122131                    $data = [
    123132                        'post_type' => $this->taxonomy,
     
    133142                        'meta_input' => $meta //(array) Array of post meta values keyed by their post meta key. Default empty.
    134143                    ];
    135                    
    136144                    if($post){
    137145                        $data['ID'] = $post->ID;
     
    178186       
    179187    }
    180 
    181     private function get_terms_tags_ids($documents){
    182        
    183         $ids = [];
     188   
     189    private function get_terms_tags_ids($documents,$id){
     190        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     191        $ids = $this->get_current_terms($id,'isp_planos_tag');
     192        //$ids = [];
    184193        foreach ($documents->resources() as $key => $doc) {
    185194            $term = term_exists( $doc->attribute('value'), 'isp_planos_tag' );
     
    191200        return $ids;
    192201    }
    193     private function get_category_ids($documents){
    194        
    195         $ids = [];
     202
     203
     204   
     205
     206    private function get_category_ids($documents,$id){
     207        $parent_id = $this->create_or_get_term_id( 'Categorias','isp_planos_category');
     208        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     209        $ids = $this->get_current_terms($id,'isp_planos_category');
     210        //$ids = [];
     211        $ids[] = $parent_id;
    196212        foreach ($documents->resources() as $key => $doc) {
    197             $term = term_exists( $doc->attribute('name'), 'isp_planos_category' );
    198             if($term){
    199                 $ids[] = $term['term_id'];
     213            $term_id = $this->create_or_get_term_id( $doc->attribute('name'), 'isp_planos_category' ,$parent_id);
     214            if($term_id){
     215                $ids[] = $term_id;
    200216            }
    201217        }
    202218        return $ids;
    203219    }
     220    private function get_cidade_category($cities,$id){
     221        $parent_id = $this->create_or_get_term_id( 'Cidades','isp_planos_category');
     222        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     223        $ids = $this->get_current_terms($id,'isp_planos_category');
     224        //$ids = [];
     225        $ids[] = $parent_id;
     226        foreach ($plans->resources() as $key => $doc) {
     227            $term_id = $this->create_or_get_term_id( $doc->attribute('name'), 'isp_planos_category' ,$parent_id);
     228            if($term_id){
     229                $ids[] = $term_id;
     230            }
     231        }
     232        return $ids;
     233    }
    204234
    205235   
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ProductCategoryApiView.php

    r2698991 r2753758  
    3838        if($response->isSuccessful()){
    3939            if($response->hasDocument()){
     40                $parent_id = $this->create_or_get_term_id( 'Categorias',$this->taxonomy);
    4041                foreach ($response->document()->primaryResources() as $key => $doc) {
    41                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    42                     $data = [
    43                         'description' => $doc->attribute('description'),
    44                         'slug' => $doc->attribute('slug'),
    45                         'parent' => null,
    46                     ];
    47                    
    48                     if($term){
    49                         $term_id = wp_update_term($term['term_id'],$this->taxonomy,$data);
    50                     }else{
    51                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    52                     }
     42                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy,$parent_id );
    5343                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5444                }
  • datacake-core/tags/1.2.9/src/Admin/ApiViews/ProductTagApiView.php

    r2698991 r2753758  
    3737            if($response->hasDocument()){
    3838                foreach ($response->document()->primaryResources() as $key => $doc) {
    39                     $term = term_exists( $doc->attribute('value'), $this->taxonomy );
    40 
    41                     $data = [
    42                         'slug' => $doc->id(),
    43                         'parent' => null,
    44                     ];
    45                    
    46                     if($term){
    47                         $term_id = wp_update_term($term['term_id'], $this->taxonomy, $data);
    48                     }else{
    49                         $term_id = wp_insert_term($doc->attribute('value'),$this->taxonomy,$data);
    50                     }
     39                    $term_id = $this->create_or_get_term_id( $doc->attribute('value'),$this->taxonomy );
    5140                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5241                }
  • datacake-core/tags/1.2.9/src/Admin/js/datacake_core-admin.js

    r2698960 r2753758  
    4545        cleanMessage();
    4646        disableBtn("#dk_core_sync_products");
    47         updateMessage("Começando aguarde ...");
     47        updateMessage("Passo 1 de 4 - Começando sincronização de categorias ...");
     48       
    4849       
    4950        // Passo 1 Baixando Categorias
    5051        recursive_sync("isp_product_category_view-sync",function(){
    5152            // Passo 1 Baixando Tags
     53            updateMessage("Passo 2 de 4 - Começando sincronização de tags de produtos ...");
    5254            recursive_sync("isp_product_tag_view-sync",function(){
    5355                // Baixando Produtos
     56                updateMessage("Passo 3 de 4 - Começando sincronização de produtos ...");
    5457                recursive_sync("isp_product_view-sync",function(){
    55                     enableBtn("#dk_core_sync_products");
    56                     updateMessage("Sincronização Concluida");
     58                    updateMessage("Passo 4 de 4 - Começando sincronização de cidades ...");
     59                    recursive_sync("isp_city_view-sync",function(){
     60                        enableBtn("#dk_core_sync_products");
     61                        updateMessage("Sincronização Concluida 🥳");
     62                    });
    5763                });
    5864            });
     
    94100        cleanMessage("canais");
    95101        //disableBtn("#dk_core_sync_canais");
    96         updateMessage("Começando aguarde ...", "canais");
     102        updateMessage("Passo 1 de 3 - Começando sincronização de categorias/grupos de canais ...", "canais");
    97103       
    98104        // Passo 1 Baixando Categorias
    99105        recursive_sync("isp_channel_group_view-sync",function(){
    100106            // Passo 1 Baixando Tags
     107            updateMessage("Passo 2 de 3 - Começando sincronização de tags/tipos de canais ...", "canais");
    101108            recursive_sync("isp_channel_type_view-sync",function(){
    102109                // Baixando Produtos
     110                updateMessage("Passo 3 de 3 - Começando sincronização de canais ...", "canais");
    103111                recursive_sync("isp_channel_view-sync",function(){
    104112                    enableBtn("#dk_core_sync_products");
    105                     updateMessage("Sincronização Concluida", "canais");
     113                    updateMessage("Sincronização concluida 🥳", "canais");
    106114                },"canais");
    107115            },"canais");
  • datacake-core/tags/1.2.9/src/Shortcodes/CityShortcode.php

    r2698960 r2753758  
    5555            'btn_text' => 'Continuar',
    5656            'ignore_neighborhood' => false,
     57            'auto_select'=>false,
    5758        ), $attrs);
    5859        $referer = isset($_GET['redirect'])?$_GET['redirect']:get_home_url();
     
    6263            $query = $query->where('is_neighborhood',false);
    6364        }
    64        
     65        $auto_select = $opt['auto_select'];
    6566        $cities = $query->get();
    6667
     
    6970            //$html .= '<form action="/home">';
    7071            $html .= '<div class id="'.$opt['group_id'].'" class="'.$opt['group_class'].'" >';
    71             $html .= '<select name="' . $opt['name'] . '" class="form-control" id="'.$opt['name'].'" aria-required="true" aria-invalid="false">';
     72            $html .= '<select name="' . $opt['name'] . '" class="form-control" id="'.$opt['name'].'" aria-required="true" aria-invalid="false" onchange="detect_city_select_change(this)">';
    7273            $html .= "<option value=''>Selecione uma cidade</option>";
    7374            $cityCookie = false;
     
    7879            }
    7980            $html .= "</select>";
    80             $html .= "<button onClick=\"send_to_page(event)\" type=\"submit\" id=\"".$opt['btn_id']."\" class=\"".$opt['btn_class']."\"> ".$opt['btn_text']." </button>";
     81            if (!$auto_select) {
     82                $html .= "<button onClick=\"send_to_page(event)\" type=\"submit\" id=\"".$opt['btn_id']."\" class=\"".$opt['btn_class']."\"> ".$opt['btn_text']." </button>";
     83            }
    8184            $html .= "</div>";
    8285            //$html .= "</form><!---->";
     
    8588                <script>
    8689                    function send_to_page(event){
    87                         event.preventDefault();
     90                        if(event.preventDefault){
     91                            event.preventDefault();
     92                        }
    8893                        var e = document.getElementById(\"".$opt['name']."\");
    8994                        var cityId = e.value;
     
    106111                            },1000);
    107112                           
     113                        }
     114                    }
     115                    function detect_city_select_change(event){
     116                        var auto_select = new Boolean($auto_select);
     117                        if(auto_select){
     118                            send_to_page(event);
    108119                        }
    109120                    }
  • datacake-core/trunk/README.md

    r2708122 r2753758  
    88* This is a Wordpress plugin, for Datacake clients and other customers who would like the functionalities
    99Based on the City you can create page redirects to show the correct page
    10 - shortcodes:
    11 dk_city_cobertura
     10 shortcodes: <--- Vai criar o formulario de cobertura
     11dk_city_cobertura
     12    Atributes of the shortcode:
     13    'success' => '😊🎉✔<br>Temos cobertura em sua cidade',
     14    'error' => 'Infelizmente sua cidade não tem cobertura ainda.<br>Qualquer dúvida entre em contato.',
     15    'assine_url' => '/assine'
    1216dk_city_list <--- This will create a list of all the cities on the system
     17    Atributes of the shortcode:
     18    'list_class' => 'g-cols via_flex valign_top type_default',
     19    'list_item_class' => 'vc_col-sm-{{col}} wpb_column vc_column_container',
     20    'col' => 3,
     21    'include_neighborhood' => false,
    1322dk_city_select <--- This will create a select with a button to save the cookie
     23    Atributes of the shortcode:
     24    'display_field' => 'name',
     25    'group_class' => 'form-group',
     26    'group_id' => 'choosecity-formgroup',
     27    'name' => 'in-cities',
     28    'select-class' => 'form-control',
     29    'btn_id' => 'chooseCitySubmit',
     30    'btn_class' => 'btn btn-outline-primary text-white',
     31    'btn_text' => 'Continuar',
     32    'ignore_neighborhood' => false,
     33    'auto_select' => false
    1434dk_city_pin <--- This will create a pin with information of the selected city
     35    Atributes of the shortcode
     36    'class' => 'pin-city',
     37    'class-marker' => 'fa fa-map-marker',
     38    'class-dropdown' => 'fa fa-chevron-down'
    1539- widgets:
    1640City SEO, this will replicate a text changing the city in the text for SEO purposes
    17 
    18 * Version: V1.2.8
     41* Version: V1.2.9
    1942
    2043
  • datacake-core/trunk/README.txt

    r2708122 r2753758  
    66Tested up to: 5.9.2
    77Requires PHP: 7.2
    8 Stable tag: 1.2.8
    9 Last Tag: 1.2.7
     8Stable tag: 1.2.9
     9Last Tag: 1.2.8
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141    'btn_text' => 'Continuar',
    4242    'ignore_neighborhood' => false,
     43    'auto_select' => false
    4344dk_city_pin <--- This will create a pin with information of the selected city
    4445    Atributes of the shortcode
  • datacake-core/trunk/datacake_core.php

    r2708122 r2753758  
    1616 * Plugin URI:        http://www.datacake.com.br
    1717 * Description:       Plugin Datacake para linkar com as Funcionalidade do Data ISP/ISP OG - Redirecionar cidade baseada no cookie
    18  * Version:           1.2.8
     18 * Version:           1.2.9
    1919 * Author:            Paulo Peres Jr
    2020 * Author URI:        https://github.com/PauloPeres
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define( 'DATACAKE_CORE_VERSION', '1.2.8' );
     38define( 'DATACAKE_CORE_VERSION', '1.2.9' );
    3939
    4040require_once __DIR__ . '/vendor/autoload.php';
  • datacake-core/trunk/src/Admin/ApiViews/AbstractApiView.php

    r2698991 r2753758  
    88    public $api;
    99    public $extraActions = [];
     10
     11    public function create_or_get_term_id($name,$taxonomy,$parent_id=0,$slug=null){
     12        $term = term_exists( $name, $taxonomy );
     13        if(!$slug){
     14            $slug = "dk_".sanitize_title($name);
     15        }
     16        $data = [
     17            'description' => $name,
     18            'slug' => $slug,
     19            'parent' => $parent_id,
     20        ];
     21       
     22        if($term){
     23            $term = wp_update_term($term['term_id'], $taxonomy ,$data);
     24        }else{
     25            $term = wp_insert_term($name, $taxonomy ,$data);
     26        }
     27        return $term['term_id'];
     28    }
     29    public function get_current_terms($id,$taxonomy, $skip_dk = true){
     30        if($id){
     31            $cur_terms = get_the_terms($id, $taxonomy);
     32            if($cur_terms){
     33                $ids = [];
     34                foreach ($cur_terms as $key => $term) {
     35                    if(!str_contains($term->slug, "dk_")){
     36                        $ids[] = $term->term_id;
     37                    }
     38                   
     39                }
     40                return $ids;
     41            }
     42        }
     43        return [];
     44    }
    1045
    1146    function register_actions($loader){
  • datacake-core/trunk/src/Admin/ApiViews/ChannelApiView.php

    r2698991 r2753758  
    8282                        }
    8383                    }
    84                    
    85                     $tags = $this->get_terms_tags_ids($doc->relationship('types'));
     84                    $post_id = $post ? $post->ID : null;
     85                    $tags = $this->get_terms_tags_ids($doc->relationship('types'),$post_id);
    8686                    $cats = array_merge(
    87                         $this->get_category_ids($doc->relationship('groups')),
    88                         $this->get_plan_category($doc->relationship('products'))
     87                        $this->get_category_ids($doc->relationship('groups'),$post_id),
     88                        $this->get_plan_category($doc->relationship('products'),$post_id)
    8989                    );
    9090                   
     
    149149    }
    150150
    151     private function get_terms_tags_ids($documents){
    152        
    153         $ids = [];
     151   
     152   
     153    private function get_terms_tags_ids($documents,$id){
     154       
     155        $ids = $this->get_current_terms($id,'isp_canais_tag');
     156       
    154157        foreach ($documents->resources() as $key => $doc) {
    155             $term = term_exists( $doc->attribute('name'), 'isp_canais_tag' );
    156             if($term){
    157               $ids[] = $doc->attribute('name');
     158            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_tag');
     159            if($term_id){
     160              $ids[] = $term_id;
    158161            }
    159162        }
     
    161164        return $ids;
    162165    }
    163     private function get_category_ids($documents){
    164         $parent_term = term_exists( 'Grupos','isp_canais_category');
    165         $ids = [];
    166         $ids[] = $parent_term['term_id'];
     166    private function get_category_ids($documents,$id){
     167        $parent_id = $this->create_or_get_term_id( 'Grupos','isp_canais_category');
     168       
     169        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     170        $ids = $this->get_current_terms($id,'isp_canais_category');
     171        //$ids = [];
     172        $ids[] = $parent_id;
    167173        foreach ($documents->resources() as $key => $doc) {
    168             $term = term_exists( $doc->attribute('name'), 'isp_canais_category' );
    169             if($term){
    170                 $ids[] = $term['term_id'];
     174            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_category',$parent_id);
     175           
     176            if($term_id){
     177                $ids[] = $term_id;
    171178            }
    172179        }
    173180        return $ids;
    174181    }
    175     private function create_or_get_parent_product_category(){
    176         $term = term_exists( 'Planos','isp_canais_category');
    177         if($term){
    178             return $term['term_id'];
    179         }
    180         $data = [
    181             'description' => 'Planos',
    182             'slug' => 'planos',
    183             'parent' => null,
    184         ];
    185        
    186         $term_id = wp_insert_term('Planos','isp_canais_category',$data);
    187         return $term_id;
    188        
    189     }
    190     private function create_or_get_term_id($doc,$parent_id){
    191         $term = term_exists( $doc->attribute('name'), 'isp_canais_category' );
    192         $data = [
    193             'description' => $doc->attribute('name'),
    194             'slug' => $doc->attribute('sku'),
    195             'parent' => $parent_id,
    196         ];
    197        
    198         if($term){
    199             $term_id = wp_update_term($term['term_id'], 'isp_canais_category' ,$data);
    200         }else{
    201             $term_id = wp_insert_term($doc->attribute('name'), 'isp_canais_category' ,$data);
    202         }
    203         return $term['term_id'];
    204     }
    205     private function get_plan_category($plans){
    206         $parent_id = $this->create_or_get_parent_product_category();
    207         $ids = [];
     182   
     183   
     184    private function get_plan_category($plans,$id){
     185        $parent_id = $this->create_or_get_term_id( 'Planos','isp_canais_category');
     186        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     187        $ids = $this->get_current_terms($id,'isp_canais_category');
     188        //$ids = [];
    208189        $ids[] = $parent_id;
    209190        foreach ($plans->resources() as $key => $doc) {
    210             $term_id = $this->create_or_get_term_id($doc,$parent_id);
     191            $term_id = $this->create_or_get_term_id($doc->attribute('name'),'isp_canais_category',$parent_id,"dk_".$doc->attribute('sku'));
    211192            if($term_id){
    212193                $ids[] = $term_id;
  • datacake-core/trunk/src/Admin/ApiViews/ChannelGroupApiView.php

    r2698991 r2753758  
    1414        ];
    1515    }
    16     private function create_or_get_parent_group_category(){
    17         $term = term_exists( 'Grupos', $this->taxonomy);
    18         if($term){
    19             return $term['term_id'];
    20         }
    21         $data = [
    22             'description' => 'Grupos',
    23             'slug' => 'grupos',
    24             'parent' => null,
    25         ];
    26        
    27         $term_id = wp_insert_term('Grupos', $this->taxonomy, $data);
    28         return $term_id;
    29        
    30     }
     16   
    3117    function sync(){
    3218       
     
    5137        if($response->isSuccessful()){
    5238            if($response->hasDocument()){
    53                 $parent_id = $this->create_or_get_parent_group_category();
     39                $parent_id = $this->create_or_get_term_id( 'Grupos',$this->taxonomy );
     40               
    5441                foreach ($response->document()->primaryResources() as $key => $doc) {
    55                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    56                     $data = [
    57                         'description' => $doc->attribute('name'),
    58                         'slug' => $doc->attribute('name'),
    59                         'parent' => $parent_id,
    60                     ];
    61                    
    62                     if($term){
    63                         $term_id = wp_update_term($term['term_id'],$this->taxonomy,$data);
    64                     }else{
    65                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    66                     }
     42                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy,$parent_id );
    6743                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    68                    
    6944                }
    7045            }else{
  • datacake-core/trunk/src/Admin/ApiViews/ChannelTypeApiView.php

    r2698991 r2753758  
    3636            if($response->hasDocument()){
    3737                foreach ($response->document()->primaryResources() as $key => $doc) {
    38                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    39 
    40                     $data = [
    41                         'slug' => $doc->id(),
    42                         'parent' => null,
    43                     ];
    44                    
    45                     if($term){
    46                         $term_id = wp_update_term($term['term_id'], $this->taxonomy, $data);
    47                     }else{
    48                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    49                     }
     38                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy );
    5039                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5140                }
  • datacake-core/trunk/src/Admin/ApiViews/CityApiView.php

    r2698991 r2753758  
    44use Datacake\Core\Admin\ApiViews\AbstractApiView;
    55use Datacake\Core\Wda\CityApi;
     6use Datacake\Core\Models\IspCity;
    67
    78class CityApiView extends AbstractApiView {
     
    910        $this->path = "isp_city_view";
    1011        $this->api = new CityApi();
     12        $this->extraActions = [
     13            "sync"
     14        ];
     15        $this->cityApi = new CityApi();
     16    }
     17    public function sync(){
     18       
     19        $message = [
     20            "status"=>"error",
     21            "mensagem" => "starting"
     22        ];
     23        $q = $this->api;
     24        $page = ["number" => 1, "size" => 15];
     25        if(isset($_POST['page'])){
     26            $page["number"] = sanitize_key($_POST['page']);
     27        }
     28       
     29        $q = $q->setJsonApiPage($page);
     30        $q = $q->setJsonApiFields([
     31            'created','updated','name','short_name',
     32                'id','code','lat','long',
     33                'redirect_url','is_neighborhood','neighborhood_name','products','products.id'
     34        ]);
     35        $q = $q->setJsonApiInclude([
     36            'products'
     37        ]);
     38       
     39        //'product_type',
     40        //'addons'
     41        //'options'
     42        //'categories'
     43        //'inventory'
     44        //'tags',
     45        $response = $q->list();
     46       
     47        if($response->isSuccessful()){
     48            if($response->hasDocument()){
     49
     50                foreach ($response->document()->primaryResources() as $key => $doc) {
     51                    $entity = IspCity::where('remote_id',$doc->id())->first();
     52                   
     53                    $data = [
     54                        'name'=>$doc->attribute('name'),
     55                        'short_name'=>$doc->attribute('short_name'),
     56                        'code'=>$doc->attribute('code')?$doc->attribute('code'):$doc->attribute('name'),
     57                        'lat'=>$doc->attribute('lat'),
     58                        'long'=>$doc->attribute('long'),
     59                        'remote_id'=>$doc->id(),
     60                        'redirect_url'=>$doc->attribute('redirect_url'),
     61                        'is_neighborhood'=>$doc->attribute('is_neighborhood'),
     62                        'neighborhood_name'=>$doc->attribute('neighborhood_name'),
     63                    ];
     64                    if($entity){
     65                        $entity->update($data);
     66                    }else{
     67                        $entity = new IspCity();
     68                        $entity->create($data);
     69                    }
     70                    $this->addCityCategoryToProducts($doc->relationship('products'),$doc);
     71                   
     72                   
     73                }
     74               
     75               
     76               
     77            }else{
     78                $message = [
     79                    "status"=>"success",
     80                    "mensagem" => "Sem Cidades"
     81                ];   
     82            }
     83        }else{
     84            // TODO GET ERROR FROM API
     85            $message = [
     86                "status"=>"error",
     87                "mensagem" => "Error from API"
     88            ];
     89        }
     90        $meta = $response->document()->meta();
     91        if($meta['pagination']['page'] < $meta['pagination']['pages']){
     92            $message = [
     93                "status"=>"success",
     94                "mensagem" => "Sincronização de cidades pagina:".$meta['pagination']['page']." de ".$meta['pagination']['pages']." concluida",
     95                "next_page" => $meta['pagination']['page'] + 1,
     96                "pagination" => $meta['pagination']
     97            ];
     98        } else {
     99            $message = [
     100                "status"=>"success",
     101                "mensagem" => "Sincronização de cidades concluida",
     102                "next_page" => null
     103            ];
     104        }
     105
     106        if($message['status'] == "error"){
     107            return wp_send_json_error($message);
     108        }
     109        return wp_send_json_success($message);
     110       
    11111    }
    12112
     113    function getPost($id){
     114        $posts = query_posts(
     115            array(
     116                'post_per_page' => 1,
     117                'post_type' => "isp_planos",
     118                'meta_query' => array(
     119                array(
     120                  'key' => 'isp_remote_id',
     121                  'value' => $id,
     122                )
     123              ),
     124            )
     125        );
     126        $post = null;
     127       
     128        if($posts && count($posts) >= 1 ){
     129            $post = $posts[0];
     130        }
     131        return $post;
     132    }
     133
     134    function addCityCategoryToProducts($documents,$city){
     135        $parent_id = $this->create_or_get_term_id( 'Cidades','isp_planos_category');
     136        foreach ($documents->resources() as $key => $doc) {
     137            $post = $this->getPost($doc->id());
     138            $ids = $this->get_current_terms($post->ID,'isp_planos_category');
     139            $ids[] = $parent_id;
     140            $term_id = $this->create_or_get_term_id( $city->attribute('name'), 'isp_planos_category' ,$parent_id);
     141            $ids[] = $term_id;
     142            wp_set_object_terms($post->ID,$ids,'isp_planos_category',true);
     143           
     144           
     145        }
     146       
     147    }
    13148}   
    14149
  • datacake-core/trunk/src/Admin/ApiViews/ProductApiView.php

    r2698991 r2753758  
    118118                        }
    119119                    }
    120                     $tags = $this->get_terms_tags_ids($doc->relationship('tags'));
    121                     $cats = $this->get_category_ids($doc->relationship('categories'));
     120                    $post_id = $post ? $post->ID : null;
     121                    $tags = $this->get_terms_tags_ids($doc->relationship('tags'),$post_id);
     122                    $cats = $this->get_category_ids($doc->relationship('categories'),$post_id);
     123                    /*
     124
     125                    $cats = array_merge(
     126                        $this->get_category_ids($doc->relationship('categories'),$post_id),
     127                        $this->get_cidade_category($doc->relationship('products'),$post_id)
     128                    );
     129                    */
     130
    122131                    $data = [
    123132                        'post_type' => $this->taxonomy,
     
    133142                        'meta_input' => $meta //(array) Array of post meta values keyed by their post meta key. Default empty.
    134143                    ];
    135                    
    136144                    if($post){
    137145                        $data['ID'] = $post->ID;
     
    178186       
    179187    }
    180 
    181     private function get_terms_tags_ids($documents){
    182        
    183         $ids = [];
     188   
     189    private function get_terms_tags_ids($documents,$id){
     190        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     191        $ids = $this->get_current_terms($id,'isp_planos_tag');
     192        //$ids = [];
    184193        foreach ($documents->resources() as $key => $doc) {
    185194            $term = term_exists( $doc->attribute('value'), 'isp_planos_tag' );
     
    191200        return $ids;
    192201    }
    193     private function get_category_ids($documents){
    194        
    195         $ids = [];
     202
     203
     204   
     205
     206    private function get_category_ids($documents,$id){
     207        $parent_id = $this->create_or_get_term_id( 'Categorias','isp_planos_category');
     208        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     209        $ids = $this->get_current_terms($id,'isp_planos_category');
     210        //$ids = [];
     211        $ids[] = $parent_id;
    196212        foreach ($documents->resources() as $key => $doc) {
    197             $term = term_exists( $doc->attribute('name'), 'isp_planos_category' );
    198             if($term){
    199                 $ids[] = $term['term_id'];
     213            $term_id = $this->create_or_get_term_id( $doc->attribute('name'), 'isp_planos_category' ,$parent_id);
     214            if($term_id){
     215                $ids[] = $term_id;
    200216            }
    201217        }
    202218        return $ids;
    203219    }
     220    private function get_cidade_category($cities,$id){
     221        $parent_id = $this->create_or_get_term_id( 'Cidades','isp_planos_category');
     222        // Não adianta pegar as tags e categorias que estão no produto por que se não na hora que uma tag for removido do wda não vai ser removida daqui
     223        $ids = $this->get_current_terms($id,'isp_planos_category');
     224        //$ids = [];
     225        $ids[] = $parent_id;
     226        foreach ($plans->resources() as $key => $doc) {
     227            $term_id = $this->create_or_get_term_id( $doc->attribute('name'), 'isp_planos_category' ,$parent_id);
     228            if($term_id){
     229                $ids[] = $term_id;
     230            }
     231        }
     232        return $ids;
     233    }
    204234
    205235   
  • datacake-core/trunk/src/Admin/ApiViews/ProductCategoryApiView.php

    r2698991 r2753758  
    3838        if($response->isSuccessful()){
    3939            if($response->hasDocument()){
     40                $parent_id = $this->create_or_get_term_id( 'Categorias',$this->taxonomy);
    4041                foreach ($response->document()->primaryResources() as $key => $doc) {
    41                     $term = term_exists( $doc->attribute('name'), $this->taxonomy );
    42                     $data = [
    43                         'description' => $doc->attribute('description'),
    44                         'slug' => $doc->attribute('slug'),
    45                         'parent' => null,
    46                     ];
    47                    
    48                     if($term){
    49                         $term_id = wp_update_term($term['term_id'],$this->taxonomy,$data);
    50                     }else{
    51                         $term_id = wp_insert_term($doc->attribute('name'),$this->taxonomy,$data);
    52                     }
     42                    $term_id = $this->create_or_get_term_id( $doc->attribute('name'),$this->taxonomy,$parent_id );
    5343                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5444                }
  • datacake-core/trunk/src/Admin/ApiViews/ProductTagApiView.php

    r2698991 r2753758  
    3737            if($response->hasDocument()){
    3838                foreach ($response->document()->primaryResources() as $key => $doc) {
    39                     $term = term_exists( $doc->attribute('value'), $this->taxonomy );
    40 
    41                     $data = [
    42                         'slug' => $doc->id(),
    43                         'parent' => null,
    44                     ];
    45                    
    46                     if($term){
    47                         $term_id = wp_update_term($term['term_id'], $this->taxonomy, $data);
    48                     }else{
    49                         $term_id = wp_insert_term($doc->attribute('value'),$this->taxonomy,$data);
    50                     }
     39                    $term_id = $this->create_or_get_term_id( $doc->attribute('value'),$this->taxonomy );
    5140                    update_term_meta( $term_id, 'wda_remote_id', $doc->id() );
    5241                }
  • datacake-core/trunk/src/Admin/js/datacake_core-admin.js

    r2698960 r2753758  
    4545        cleanMessage();
    4646        disableBtn("#dk_core_sync_products");
    47         updateMessage("Começando aguarde ...");
     47        updateMessage("Passo 1 de 4 - Começando sincronização de categorias ...");
     48       
    4849       
    4950        // Passo 1 Baixando Categorias
    5051        recursive_sync("isp_product_category_view-sync",function(){
    5152            // Passo 1 Baixando Tags
     53            updateMessage("Passo 2 de 4 - Começando sincronização de tags de produtos ...");
    5254            recursive_sync("isp_product_tag_view-sync",function(){
    5355                // Baixando Produtos
     56                updateMessage("Passo 3 de 4 - Começando sincronização de produtos ...");
    5457                recursive_sync("isp_product_view-sync",function(){
    55                     enableBtn("#dk_core_sync_products");
    56                     updateMessage("Sincronização Concluida");
     58                    updateMessage("Passo 4 de 4 - Começando sincronização de cidades ...");
     59                    recursive_sync("isp_city_view-sync",function(){
     60                        enableBtn("#dk_core_sync_products");
     61                        updateMessage("Sincronização Concluida 🥳");
     62                    });
    5763                });
    5864            });
     
    94100        cleanMessage("canais");
    95101        //disableBtn("#dk_core_sync_canais");
    96         updateMessage("Começando aguarde ...", "canais");
     102        updateMessage("Passo 1 de 3 - Começando sincronização de categorias/grupos de canais ...", "canais");
    97103       
    98104        // Passo 1 Baixando Categorias
    99105        recursive_sync("isp_channel_group_view-sync",function(){
    100106            // Passo 1 Baixando Tags
     107            updateMessage("Passo 2 de 3 - Começando sincronização de tags/tipos de canais ...", "canais");
    101108            recursive_sync("isp_channel_type_view-sync",function(){
    102109                // Baixando Produtos
     110                updateMessage("Passo 3 de 3 - Começando sincronização de canais ...", "canais");
    103111                recursive_sync("isp_channel_view-sync",function(){
    104112                    enableBtn("#dk_core_sync_products");
    105                     updateMessage("Sincronização Concluida", "canais");
     113                    updateMessage("Sincronização concluida 🥳", "canais");
    106114                },"canais");
    107115            },"canais");
  • datacake-core/trunk/src/Shortcodes/CityShortcode.php

    r2698960 r2753758  
    5555            'btn_text' => 'Continuar',
    5656            'ignore_neighborhood' => false,
     57            'auto_select'=>false,
    5758        ), $attrs);
    5859        $referer = isset($_GET['redirect'])?$_GET['redirect']:get_home_url();
     
    6263            $query = $query->where('is_neighborhood',false);
    6364        }
    64        
     65        $auto_select = $opt['auto_select'];
    6566        $cities = $query->get();
    6667
     
    6970            //$html .= '<form action="/home">';
    7071            $html .= '<div class id="'.$opt['group_id'].'" class="'.$opt['group_class'].'" >';
    71             $html .= '<select name="' . $opt['name'] . '" class="form-control" id="'.$opt['name'].'" aria-required="true" aria-invalid="false">';
     72            $html .= '<select name="' . $opt['name'] . '" class="form-control" id="'.$opt['name'].'" aria-required="true" aria-invalid="false" onchange="detect_city_select_change(this)">';
    7273            $html .= "<option value=''>Selecione uma cidade</option>";
    7374            $cityCookie = false;
     
    7879            }
    7980            $html .= "</select>";
    80             $html .= "<button onClick=\"send_to_page(event)\" type=\"submit\" id=\"".$opt['btn_id']."\" class=\"".$opt['btn_class']."\"> ".$opt['btn_text']." </button>";
     81            if (!$auto_select) {
     82                $html .= "<button onClick=\"send_to_page(event)\" type=\"submit\" id=\"".$opt['btn_id']."\" class=\"".$opt['btn_class']."\"> ".$opt['btn_text']." </button>";
     83            }
    8184            $html .= "</div>";
    8285            //$html .= "</form><!---->";
     
    8588                <script>
    8689                    function send_to_page(event){
    87                         event.preventDefault();
     90                        if(event.preventDefault){
     91                            event.preventDefault();
     92                        }
    8893                        var e = document.getElementById(\"".$opt['name']."\");
    8994                        var cityId = e.value;
     
    106111                            },1000);
    107112                           
     113                        }
     114                    }
     115                    function detect_city_select_change(event){
     116                        var auto_select = new Boolean($auto_select);
     117                        if(auto_select){
     118                            send_to_page(event);
    108119                        }
    109120                    }
Note: See TracChangeset for help on using the changeset viewer.