Plugin Directory

Changeset 3042581


Ignore:
Timestamp:
02/28/2024 01:00:49 PM (2 years ago)
Author:
knhar
Message:

news and fixed

Location:
presta-products/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • presta-products/trunk/presta-products.php

    r3041947 r3042581  
    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.24
     6 * Version:             1.1.25
    77 * Requires at least:   5.2
    88 * Requires PHP:        7.2
     
    390390                            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    391391                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     392                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     393                            curl_setopt($ch, CURLOPT_TIMEOUT, 15);
     394                            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     395                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    392396                           
    393397                            // Exécution du curl
  • presta-products/trunk/readme.txt

    r3041947 r3042581  
    66Requires PHP: 5.6
    77Tested up to: 6.4.3
    8 Stable tag: 1.1.24
     8Stable tag: 1.1.25
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6363
    6464== Changelog ==
     65
     66= 1.1.25 = (28/02/2024)
     67* Fixed: quelques correctifs mineurs apportés (sécurité d'appels API)
    6568
    6669= 1.1.24 = (27/02/2024)
  • presta-products/trunk/scripts/cron/crontab-presta-products.php

    r2809664 r3042581  
    7676        // Initialisation du tableau des produits
    7777        $products = array();
    78 
    79         // 1 produit
    80         if (isset($atts['product'])) {
    81             $url[] = $prestashop_url . '/api/products/' . $atts['product'] . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
    82         }
    83         // Plusieurs produits
    84         else if (isset($atts['products'])) {
    85             $ids = explode(',', $atts['products']);
    86            
    87             foreach ($ids as $id) {
    88                 $url[] = $prestashop_url . '/api/products/' . $id . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
    89             }
    90         }
    91         else if (isset($atts['bestsellers'])) {
     78   
     79        // GBO - 1.1.21
     80        // Gestion Bestsellers
     81        if (isset($atts['bestsellers'])) {
    9282            // Nombre de jours en arrière
    9383            $days   = (isset($atts['bestsellers']) && intval($atts['bestsellers'])) ? $atts['bestsellers'] : 10;
     
    115105                // Fonctions de traitement du tableau
    116106                arsort($_products);
    117                 $_products = array_keys($_products);
    118                 array_splice($_products, $limit);
    119 
    120                 // Récupération produit
    121                 foreach ($_products as $element) {
    122                     $url[] = $prestashop_url . '/api/products/' . $element . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
    123                 }
     107                //$_products = array_keys($_products);
     108               
     109                // Si un 2ème paramètre en plus de bestsellers
     110                if (isset($atts['product'])) {
     111                    if (array_key_exists($atts['product'], $_products)) {
     112                        $url[] = $prestashop_url . '/api/products/' . $atts['product'] . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     113                    }
     114                }
     115                else if (isset($atts['products'])) {
     116                    $ids = explode(',', $atts['products']);
     117           
     118                    foreach ($ids as $id) {
     119                        if (array_key_exists($id, $_products)) {
     120                            $url[] = $prestashop_url . '/api/products/' . $id . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     121                        }
     122                    }
     123                }
     124                else if (isset($atts['category'])) {
     125                    // Appel HTTP API
     126                    $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $atts['category'] . ']&ws_key=' . $webservice_key . '&output_format=JSON';
     127                    $response   = wp_remote_get( $link );
     128                    $body       = wp_remote_retrieve_body( $response );
     129                    $http_code  = wp_remote_retrieve_response_code( $response );
     130       
     131                    if ($http_code == '200') {
     132                        // Produit (format JSON > Array)
     133                        $result = json_decode($body);
     134
     135                        foreach ($result->products as $element) {
     136                            if (array_key_exists($element->id, $_products)) {
     137                                $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';
     138                            }
     139                        }
     140                    }
     141                }
     142                else if (isset($atts['categories'])) {
     143                    $ids = explode(',', $atts['categories']);
     144           
     145                    foreach ($ids as $id) {
     146                        // Appel HTTP API
     147                        $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $id . ']&ws_key=' . $webservice_key . '&output_format=JSON';
     148                        $response   = wp_remote_get( $link );
     149                        $body       = wp_remote_retrieve_body( $response );
     150                        $http_code  = wp_remote_retrieve_response_code( $response );
     151           
     152                        if ($http_code == '200') {
     153                            // Produit (format JSON > Array)
     154                            $result = json_decode($body);
     155
     156                            foreach ($result->products as $element) {
     157                                if (array_key_exists($element->id, $_products)) {
     158                                    $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';
     159                                }
     160                            }
     161                        }
     162                    }
     163                }
     164                else {
     165                    // Fonctions de traitement du tableau
     166                    array_splice($_products, $limit);
     167
     168                    // Récupération produit
     169                    foreach ($_products as $element) {
     170                        $url[] = $prestashop_url . '/api/products/' . $element . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     171                    }
     172                }
     173
     174                // Fonctions de traitement du tableau
     175                array_splice($url, $limit);
     176            }
     177        }
     178        // 1 produit
     179        else if (isset($atts['product'])) {
     180            $url[] = $prestashop_url . '/api/products/' . $atts['product'] . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
     181        }
     182        // Plusieurs produits
     183        else if (isset($atts['products'])) {
     184            $ids = explode(',', $atts['products']);
     185           
     186            foreach ($ids as $id) {
     187                $url[] = $prestashop_url . '/api/products/' . $id . '?price[my_price][use_tax]=1&price[old_price][only_reduction]=1&ws_key=' . $webservice_key . '&output_format=JSON';
    124188            }
    125189        }
     
    162226            }
    163227        }
     228           
     229        // V1.1.19 - BEGIN - Ajout de la gestion WPML
     230        // WPML : Récupération des langues de Prestashop. Nécessite le Webservice "languages"
     231        $wpml_languages = apply_filters( 'wpml_active_languages', null );
     232        if (isset($wpml_languages) && !is_null($wpml_languages) && !empty($wpml_languages)) {
     233            foreach($wpml_languages as $languages) {
     234                if ($languages['active']) {
     235                    $langue_actuel  = $languages['language_code'];//default_locale'];
     236                    break;
     237                }
     238            }
     239            $link           = $prestashop_url . '/api/languages/?display=[id,iso_code]&ws_key=' . $webservice_key . '&output_format=JSON';
     240            $response       = wp_remote_get( $link );
     241            $body           = wp_remote_retrieve_body( $response );
     242            $http_code      = wp_remote_retrieve_response_code( $response );
     243           
     244            if ($http_code == '200') {
     245                $prest_languages = json_decode($body);
     246            }
     247        }
     248        // V1.1.19 - END
    164249       
    165250        // Polylang : Récupération des langues de Prestashop. Nécessite le Webservice "languages"
     
    175260            }
    176261        }
     262       
     263        // Si l'utilisateur force la langue
     264        if (isset($atts['language'])) {
     265            $langue_actuel  = $atts['language'];
     266            $link           = $prestashop_url . '/api/languages/?display=[id,iso_code]&ws_key=' . $webservice_key . '&output_format=JSON';
     267            $response       = wp_remote_get( $link );
     268            $body           = wp_remote_retrieve_body( $response );
     269            $http_code      = wp_remote_retrieve_response_code( $response );
     270           
     271            if ($http_code == '200') {
     272                $prest_languages = json_decode($body);
     273            }
     274        }
    177275       
    178276        // Récupération des produits
     
    190288                if (isset($product->product)) {
    191289                    // Si on veut cacher des produits
    192                     if ($product->product->active == 0 && $hide_inactive) {
     290                    if (isset($product->product->active) && $product->product->active == 0 && $hide_inactive) {
    193291                        continue;
    194292                    }
    195                     else if ($product->product->available_for_order == 0 && $hide_available) {
     293                    else if (isset($product->product->available_for_order) && $product->product->available_for_order == 0 && $hide_available) {
    196294                        continue;
    197295                    }
    198                     else if ($product->product->visibility == 'none' && $hide_visibility) {
     296                    else if (isset($product->product->visibility) && $product->product->visibility == 'none' && $hide_visibility) {
     297                        continue;
     298                    }
     299                    else if (isset($product->product->quantity) && $product->product->quantity <= 0 && $hide_stock) {
    199300                        continue;
    200301                    }
     
    205306                   
    206307                    // Récupération de la redirection par les méthodes WP
    207                     if (isset($url_rewrite_element['headers']) && isset($url_rewrite_element['headers']['location'])) {
     308                    if (is_array($url_rewrite_element) && isset($url_rewrite_element['headers']) && isset($url_rewrite_element['headers']['location'])) {
    208309                        $product->url_rewrite = $url_rewrite_element['headers']['location'];
    209310                    }
     
    211312                    // Récupération de la redirection par les fonctions PHP (si la précédente n'a pas marché)
    212313                    if (empty($product->url_rewrite) || !isset($product->url_rewrite)) {
    213                         $product->url_rewrite = get_headers($url_rewrite, 1)['Location'];
     314                        $get_headers = get_headers($url_rewrite, 1);
     315                       
     316                        if (isset($get_headers['Location'])) {
     317                            $product->url_rewrite = $get_headers['Location'];
     318                        }
    214319                    }
    215320                   
     
    224329                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    225330                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     331                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     332                        curl_setopt($ch, CURLOPT_TIMEOUT, 15);
     333                        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     334                        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     335
    226336                       
    227337                        // Exécution du curl
     
    232342                        $product->url_rewrite = $url;
    233343                    }
    234                    
    235                     // URL par défaut (si aucune redirection n'est trouvée)
    236                     if (empty($product->url_rewrite) || !isset($product->url_rewrite)) {
    237                         if (is_array($product->product->link_rewrite) && count($product->product->link_rewrite) > 0) {
    238                             $link_rewrite = $product->product->link_rewrite[0]->value;
    239                         }
    240                         else {
    241                             $link_rewrite = $product->product->link_rewrite;
    242                         }
    243                        
    244                         $product->url_rewrite = $prestashop_url . '/' . $product->product->id . ((isset($product->product->id_default_combination) && !empty($product->product->id_default_combination)) ? '-' . $product->product->id_default_combination : '' ) . '-' . $link_rewrite .'.html';
    245                     }
    246                    
     344                       
    247345                    // Gestion de la langue par défaut
    248346                    $id_lang = 1;
    249347                                           
    250                     // Gestion de la langue avec Polylang
     348                    // Gestion de la langue avec Polylang OU WPML
    251349                    if (isset($prest_languages) and !empty($prest_languages) and is_array($prest_languages->languages) and count($prest_languages->languages) > 0) {
    252350                        foreach($prest_languages->languages as $key => $prest_language) {
     
    269367                        $product->product->description          = $product->product->description[$keyToSave]->value;
    270368                        $product->product->description_short    = $product->product->description_short[$keyToSave]->value;
     369                        // V1.1.19 - BEGIN - Gestion du lien produit dans la langue également
     370                        $product->product->link_rewrite         = (isset($product->product->link_rewrite) && !empty($keyToSave) && isset($product->product->link_rewrite[$keyToSave])) ? $product->product->link_rewrite[$keyToSave]->value : '';
     371                        $product->product->url_rewrite          = (isset($product->product->url_rewrite) && !empty($keyToSave) && isset($product->product->url_rewrite[$keyToSave])) ? $product->product->url_rewrite[$keyToSave]->value : '';
     372                        // V1.1.19 - END
     373                    }
     374                   
     375                    // URL par défaut (si aucune redirection n'est trouvée)
     376                    if (empty($product->url_rewrite) || !isset($product->url_rewrite) || isset($atts['language'])) { // !empty($product->product->link_rewrite)
     377                        if (is_array($product->product->link_rewrite) && count($product->product->link_rewrite) > 0) {
     378                            $link_rewrite = $product->product->link_rewrite[0]->value;
     379                        }
     380                        else {
     381                            $link_rewrite = $product->product->link_rewrite;
     382                        }
     383                       
     384                        $product->url_rewrite = $prestashop_url . '/' . (($atts['language']) ? $atts['language'] . '/' : '') . $product->product->id . ((isset($product->product->id_default_combination) && !empty($product->product->id_default_combination)) ? '-' . $product->product->id_default_combination : '' ) . '-' . $link_rewrite .'.html';
    271385                    }
    272386                   
Note: See TracChangeset for help on using the changeset viewer.