Plugin Directory

Changeset 3183727


Ignore:
Timestamp:
11/07/2024 10:42:39 AM (16 months ago)
Author:
knhar
Message:

news and fixed

Location:
presta-products/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • presta-products/trunk/assets/javascript/ppgbo-admin.js

    r2853481 r3183727  
    7373        });
    7474    });
     75   
     76    // Bouton de suppression d'une correspondance
     77    $('.deleteCorrespondance').on('click', function(e) {
     78        var params = {
     79            'action': 'deleteCorrespondance',
     80            'id': $(this).attr('data-id')
     81        };
     82       
     83        $.post(ppgbo_ajax.url, params, function(response) {
     84            location.reload();
     85        });
     86    });
    7587});
  • presta-products/trunk/includes/admin-header.php

    r2690016 r3183727  
    2020            <a href="admin.php?page=presta-products&amp;tab=cache" class="nav-tab <?php echo (($page == 'cache') ? 'nav-tab-active' : ''); ?>"><?php echo __( 'Cache', 'presta-products' ); ?></a>
    2121            <a href="admin.php?page=presta-products&amp;tab=used" class="nav-tab <?php echo (($page == 'used') ? 'nav-tab-active' : ''); ?>"><?php echo __( 'Utilisé sur', 'presta-products' ); ?></a>
     22            <a href="admin.php?page=presta-products&amp;tab=categories" class="nav-tab <?php echo (($page == 'categories') ? 'nav-tab-active' : ''); ?>"><?php echo __( 'Correspondances des catégories', 'presta-products' ); ?></a>
    2223        <?php
    2324            }
     
    2627            <a href="javascript:;" class="nav-tab" title="<?php echo __( 'Uniquement en version PREMIUM.', 'presta-products' ); ?>"><?php echo __( 'Cache (Option PREMIUM)', 'presta-products' ); ?></a>
    2728            <a href="javascript:;" class="nav-tab" title="<?php echo __( 'Uniquement en version PREMIUM.', 'presta-products' ); ?>"><?php echo __( 'Utilisé sur (Option PREMIUM)', 'presta-products' ); ?></a>
     29            <a href="javascript:;" class="nav-tab" title="<?php echo __( 'Uniquement en version PREMIUM.', 'presta-products' ); ?>"><?php echo __( 'Correspondances des catégories (Option PREMIUM)', 'presta-products' ); ?></a>
    2830        <?php   
    2931            }
  • presta-products/trunk/includes/tabs/examples.php

    r3002286 r3183727  
    2929    </div>
    3030    <hr>
     31    <?php
     32        if ($freemium) {
     33    ?>
     34    <div class="mt-3">
     35        <h5><?php echo __( 'Catégories (correspondances)', 'presta-products'); ?></h5>
     36        <code>auto_category="1"</code><br>
     37        <i><?php echo __( 'Utilise l\'onglet Correspondance des catégories pour afficher les produits correspondant à la catégorie Wordpress en cours.<br>PREMIUM seulement.', 'presta-products'); ?></i>
     38    </div>
     39    <hr>
     40    <?php
     41        }
     42    ?>
    3143    <div class="mt-3">
    3244        <h5><?php echo __( 'Nombre de produits', 'presta-products'); ?></h5>
  • presta-products/trunk/presta-products.php

    r3116878 r3183727  
    44 * Plugin URI:          https://www.guillaume-bouaud.fr/produit/presta-products-for-wordpress 
    55 * Description:         Affichage des produits Prestashop sur le site internet généré par Wordpress.
    6  * Version:             1.1.27
     6 * Version:             1.2.0
    77 * Requires at least:   5.2
    88 * Requires PHP:        7.2
     
    7777        add_option( 'ppgbo_premium_key', '' );
    7878        add_option( 'ppgbo_premium_userId', '' );
     79        // GBO - 1.2.0
     80        add_option( 'ppgbo_use_categories', 0 );
    7981       
    8082        // Création de la table MYQSL
     
    115117                update_option( 'ppgbo_new_tab', '1' );
    116118                update_option( 'ppgbo_use_cache', 0);
     119                update_option( 'ppgbo_use_categories', 0);
    117120            }
    118121            // Si on est à moins de 5 connexions échouées vers le serveur
     
    137140            // Initialisation du tableau des produits
    138141            $products = array();
    139    
     142           
    140143            // GBO - 1.1.21
    141144            // Gestion Bestsellers
     
    183186                        }
    184187                    }
     188                    else if (isset($atts['auto_category'])) {
     189                        $id_category = $this::getCorrespondance(get_the_category()[0]->cat_ID);
     190                       
     191                        // Appel HTTP API
     192                        $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $id_category . ']&ws_key=' . $webservice_key . '&output_format=JSON';
     193                        $response   = wp_remote_get( $link );
     194                        $body       = wp_remote_retrieve_body( $response );
     195                        $http_code  = wp_remote_retrieve_response_code( $response );
     196           
     197                        if ($http_code == '200') {
     198                            // Produit (format JSON > Array)
     199                            $result = json_decode($body);
     200
     201                            foreach ($result->products as $element) {
     202                                if (array_key_exists($element->id, $_products)) {
     203                                    $url[] = $prestashop_url . '/api/products/' . $element->id . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     204                                }
     205                            }
     206                        }
     207                    }
    185208                    else if (isset($atts['category'])) {
    186209                        // Appel HTTP API
     
    249272                }
    250273            }
     274            // Correspondance Catégories
     275            else if (isset($atts['auto_category'])) {
     276                $id_category = getCorrespondance(get_the_category()[0]->cat_ID);
     277
     278                // Appel HTTP API
     279                $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $id_category . ']&limit=' . $limit . '&ws_key=' . $webservice_key . '&output_format=JSON';
     280                $response   = wp_remote_get( $link );
     281                $body       = wp_remote_retrieve_body( $response );
     282                $http_code  = wp_remote_retrieve_response_code( $response );
     283           
     284                if ($http_code == '200') {
     285                    // Produit (format JSON > Array)
     286                    $result = json_decode($body);
     287
     288                    foreach ($result->products as $element) {
     289                        $url[] = $prestashop_url . '/api/products/' . $element->id . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     290                    }
     291                }
     292            }
    251293            // Catégorie
    252294            else if (isset($atts['category'])) {
     
    590632            return $a->product->quantity < $b->product->quantity;
    591633        }
     634   
     635        // Suppression d'une correspondance
     636        function ppgbo_delete_correspondance() {
     637            global $wpdb;
     638           
     639            $id = $_POST['id'];
     640           
     641            // Réinit la base
     642            $myTable    = $wpdb->prefix.'ppgbo_categories';
     643            $sql        = $wpdb->prepare("DELETE FROM %i WHERE id = %d", $myTable, $id);
     644            $wpdb->query($sql) or wp_die(__( 'Problème de suppression de la correspondance.', 'presta-products' ));
     645           
     646            echo __( 'Correspondance supprimée.', 'presta-products' );
     647                   
     648            // On arrête l'ajax
     649            wp_die();
     650        }
     651       
     652        add_action( 'wp_ajax_deleteCorrespondance', 'ppgbo_delete_correspondance' );
    592653
    593654        // Fonction de changement des shortcodes
     
    599660            {
    600661                // Si pas un des champs obligatoire, on passe
    601                 if (!isset($atts['product']) && !isset($atts['products']) && !isset($atts['category']) && !isset($atts['categories']) && !isset($atts['bestsellers']))
     662                if (!isset($atts['product']) && !isset($atts['products']) && !isset($atts['category']) && !isset($atts['categories']) && !isset($atts['bestsellers']) && !isset($atts['auto_category']))
    602663                {
    603664                    return "";   
     
    636697                $arrows_carrousel           = get_option( 'ppgbo_arrows_carrousel' );
    637698                $dots_carrousel             = get_option( 'ppgbo_dots_carrousel' );
     699                $use_categories             = get_option( 'ppgbo_use_categories' );
    638700
    639701                // Obfuscation forcée
     
    792854        add_filter('parent_file', 'presta_product_g_highlight_submenu');
    793855   
     856        // Correspondance
     857        function getCorrespondance($id_cat_wp) {
     858            global $wpdb;
     859           
     860            $myTable    = $wpdb->prefix.'ppgbo_categories';
     861            $sql        = $wpdb->prepare("SELECT id_cat_prestashop FROM $myTable WHERE id_cat_wordpress = %d", $id_cat_wp);
     862           
     863            return $wpdb->get_results($sql)[0]->id_cat_prestashop;
     864        }
    794865    }
    795866   
     
    849920                'used_page'
    850921            );
     922            add_submenu_page(
     923                'presta-products',
     924                __( 'Correspondances', 'presta-products' ),
     925                __( 'Correspondances', 'presta-products' ),
     926                'manage_options',
     927                'presta-products&tab=categories',
     928                'categories_page'
     929            );
    851930        }
    852931    }
     
    858937        // URL de récupération de la clé
    859938        $link       = base64_decode($prefix) . base64_decode($licence) . $key . '?consumer_key=' . base64_decode($consumer) . '&consumer_secret=' . base64_decode($secret);
     939        $args       = $args = array(
     940            'headers' => array(
     941                'Referer' => get_site_url(),
     942            ),
     943        );
    860944
    861945        // HTTP API
    862         $response   = wp_remote_get( $link );
     946        $response   = wp_remote_get( $link, $args );
    863947        $body       = wp_remote_retrieve_body( $response );
    864948        //$http_code  = wp_remote_retrieve_response_code( $response );
     
    881965    public function load_ppgbo_plugin_page()
    882966    {
     967        global $wpdb;
     968       
    883969        // Sécurité : si on est sur le back office
    884970        if ( is_admin() ) {
     
    9891075                // Gestion du message d'information
    9901076                update_option( 'ppgbo_message', __('Gestion du cache enregistrée.', 'presta-products') );
     1077            }
     1078            // Formulaire des catégories
     1079            else if (isset($_POST['type']) && $_POST['type'] == 'categories') {
     1080                $use_categories             = (isset($_POST['use_categories'])) ? 1 : 0;
     1081   
     1082                // Modification des options
     1083                update_option( 'ppgbo_use_categories', $use_categories );   
     1084   
     1085                // Gestion du message d'information
     1086                update_option( 'ppgbo_message', __('Gestion de la correspondance des catégories enregistrée.', 'presta-products') );
     1087            }
     1088            // Formulaire des catégories (correspondances)
     1089            else if (isset($_POST['type']) && $_POST['type'] == 'correspondances_cat') {
     1090                $id_cat_wordpress   = (isset($_POST['id_cat_wordpress'])) ? sanitize_text_field($_POST['id_cat_wordpress']) : 0;
     1091                $id_cat_prestashop  = (isset($_POST['id_cat_prestashop'])) ? sanitize_text_field($_POST['id_cat_prestashop']) : 0;
     1092                $id                 = (isset($_POST['id']) && !empty($_POST['id'])) ? sanitize_text_field($_POST['id']) : 0;
     1093               
     1094                if ($id_cat_wordpress > 0 && $id_cat_prestashop > 0) {
     1095                    $myTable    = $wpdb->prefix.'ppgbo_categories';
     1096                   
     1097                    if ($id > 0) {
     1098                        // Requête SQL de modification
     1099                        $sql        = $wpdb->prepare("UPDATE $myTable SET id_cat_wordpress = %d, id_cat_prestashop = %d WHERE id = %d", intval($id_cat_wordpress), intval($id_cat_prestashop), intval($id));
     1100                    }
     1101                    else {
     1102                        // Requête SQL d'ajout
     1103                        $sql        = $wpdb->prepare("INSERT IGNORE INTO $myTable (id_cat_wordpress, id_cat_prestashop) VALUES (%d, %d)", intval($id_cat_wordpress), intval($id_cat_prestashop));
     1104                    }
     1105                   
     1106                    $result     = $wpdb->query($sql);
     1107               
     1108                    if ($result === false) {
     1109                        // Gestion du message d'information
     1110                        update_option( 'ppgbo_message', __('Problème lors de l\'enregistrement de la correspondance de la catégorie.', 'presta-products') );
     1111                    }
     1112                }
    9911113            }
    9921114           
     
    10221144            $arrows_carrousel           = get_option( 'ppgbo_arrows_carrousel' );
    10231145            $dots_carrousel             = get_option( 'ppgbo_dots_carrousel' );
     1146            $use_categories             = get_option( 'ppgbo_use_categories' );
    10241147            $counter_freemium           = 5 - (get_option( 'ppgbo_counter_freemium' ));
    10251148            $freemium                   = $this->is_freemium;
    1026             $page                       = (isset($_GET['tab']) && in_array($_GET['tab'], array('options', 'features', 'examples', 'used', 'cache'))) ? sanitize_text_field($_GET['tab']) : ((isset($_GET['tab']) && !in_array($_GET['tab'], array('options', 'features', 'examples', 'used', 'cache'))) ? '404' : 'options');
     1149            $page                       = (isset($_GET['tab']) && in_array($_GET['tab'], array('options', 'features', 'examples', 'used', 'cache', 'categories'))) ? sanitize_text_field($_GET['tab']) : ((isset($_GET['tab']) && !in_array($_GET['tab'], array('options', 'features', 'examples', 'used', 'cache', 'categories'))) ? '404' : 'options');
    10271150            $list                       = $this->ppgbo_getListing();
    10281151            $caches                     = $this->ppgbo_get_cache();
     1152            $categories                 = get_categories();
     1153            $correspondances            = $this->ppgbo_get_correspondances();
     1154            $correspondance             = ($_GET['id']) ? $this->ppgbo_get_correspondances($_GET['id']) : null;
    10291155            $product_template_1         = plugins_url( 'assets/images/product-template-1.png', __FILE__ );
    10301156            $product_template_2         = plugins_url( 'assets/images/product-template-2.png', __FILE__ );
     
    10411167            $dots_carrousel_2           = plugins_url( 'assets/images/circle.svg', __FILE__ );
    10421168            $script_cron                = plugin_dir_path( __FILE__ ) . plugin_dir_path( 'scripts/cron/crontab-presta-products.php' ) . 'crontab-presta-products.php';
    1043            
     1169
    10441170            // Gestion du message d'information
    10451171            $message                    = get_option( 'ppgbo_message' );
     
    10551181                include 'includes/tabs/cache.php';
    10561182                include 'includes/tabs/used.php';
     1183                include 'includes/tabs/categories.php';
    10571184            }
    10581185           
     
    11591286        dbDelta($simple_sql);
    11601287           
    1161         // Check if tables not exist yet
    1162         if (!$this->ppgbo_check_table_exists('ppgbo_cache')) {
    1163             // Index unique
    1164             $simple_sql = "CREATE UNIQUE INDEX shortcode_index ON {$wpdb->prefix}ppgbo_cache ( shortcode );";
    1165             $wpdb->query( $simple_sql );
    1166         }
     1288        // Index unique
     1289        $simple_sql = "CREATE UNIQUE INDEX shortcode_index ON {$wpdb->prefix}ppgbo_cache ( shortcode );";
     1290        $wpdb->query( $simple_sql );
     1291
     1292        // 1.2.0 : ajout de la correspondance des catégories
     1293        // Création de la table
     1294        $simple_sql = "CREATE TABLE {$wpdb->prefix}ppgbo_categories (
     1295                 id bigint(20) unsigned NOT NULL auto_increment,
     1296                 id_cat_wordpress bigint(20) NOT NULL default 0,
     1297                 id_cat_prestashop bigint(20) NOT NULL default 0,
     1298                 PRIMARY KEY  (id)
     1299                ) {$charset_collate};";
     1300       
     1301        // Vérifie si des modifications
     1302        dbDelta($simple_sql);
     1303       
     1304        // Index unique
     1305        $simple_sql = "CREATE UNIQUE INDEX id_cat_index ON {$wpdb->prefix}ppgbo_categories ( id_cat_wordpress );";
     1306        $wpdb->query( $simple_sql );
    11671307    }
    11681308   
     
    11961336    }
    11971337   
     1338    public function ppgbo_get_correspondances($id = null) {
     1339        global $wpdb;
     1340
     1341        $datas      = array();
     1342        $myTable    = $wpdb->prefix.'ppgbo_categories';
     1343        $sql        = "SELECT * FROM %i";
     1344       
     1345        if ($id > 0) {
     1346            $sql .= " WHERE id = " . $id;
     1347        }
     1348       
     1349        $result     = $wpdb->prepare($sql, $myTable);       
     1350        return $wpdb->get_results($result);
     1351    }
     1352   
    11981353    // Vérification si la table existe
    11991354    public function ppgbo_check_table_exists( $tablename ) {
  • presta-products/trunk/readme.txt

    r3116878 r3183727  
    66Requires PHP: 5.6
    77Tested up to: 6.4.3
    8 Stable tag: 1.1.27
     8Stable tag: 1.2.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6363
    6464== Changelog ==
     65
     66= 1.2.0 = (07/11/2024)
     67* Testée jusqu’à la version 6.6.2 de WordPress
     68* Nouveau: Gestion de matching des catégories Prestashop avec des catégories WP (PREMIUM)
     69* Fixed: Amélioration des flux API
    6570
    6671= 1.1.27 = (12/07/2024)
Note: See TracChangeset for help on using the changeset viewer.