Plugin Directory

Changeset 3032206


Ignore:
Timestamp:
02/06/2024 02:11:59 PM (2 years ago)
Author:
knhar
Message:

news and fixed

Location:
presta-products/trunk
Files:
2 edited

Legend:

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

    r3002286 r3032206  
    137137            // Initialisation du tableau des produits
    138138            $products = array();
    139    
    140             // 1 produit
    141             if (isset($atts['product'])) {
    142                 $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';
    143             }
    144             // Plusieurs produits
    145             else if (isset($atts['products'])) {
    146                 $ids = explode(',', $atts['products']);
    147                
    148                 foreach ($ids as $id) {
    149                     $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';
    150                 }
    151             }
    152             else if (isset($atts['bestsellers'])) {
     139
     140            // GBO - 1.1.20
     141            // Gestion Bestsellers
     142            if (isset($atts['bestsellers'])) {
    153143                // Nombre de jours en arrière
    154144                $days   = (isset($atts['bestsellers']) && intval($atts['bestsellers'])) ? $atts['bestsellers'] : 10;
     
    177167                    arsort($_products);
    178168                    $_products = array_keys($_products);
    179                     array_splice($_products, $limit);
    180 
    181                     // Récupération produit
    182                     foreach ($_products as $element) {
    183                         $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';
    184                     }
     169                   
     170                    // Si un 2ème paramètre en plus de bestsellers
     171                    if (isset($atts['product'])) {
     172                        if (array_key_exists($atts['product'], $_products)) {
     173                            $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';
     174                        }
     175                    }
     176                    else if (isset($atts['products'])) {
     177                        $ids = explode(',', $atts['products']);
     178               
     179                        foreach ($ids as $id) {
     180                            if (array_key_exists($id, $_products)) {
     181                                $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';
     182                            }
     183                        }
     184                    }
     185                    else if (isset($atts['category'])) {
     186                        // Appel HTTP API
     187                        $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $atts['category'] . ']&ws_key=' . $webservice_key . '&output_format=JSON';
     188                        $response   = wp_remote_get( $link );
     189                        $body       = wp_remote_retrieve_body( $response );
     190                        $http_code  = wp_remote_retrieve_response_code( $response );
     191           
     192                        if ($http_code == '200') {
     193                            // Produit (format JSON > Array)
     194                            $result = json_decode($body);
     195
     196                            foreach ($result->products as $element) {
     197                                if (array_key_exists($element->id, $_products)) {
     198                                    $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';
     199                                }
     200                            }
     201                        }
     202                    }
     203                    else if (isset($atts['categories'])) {
     204                        $ids = explode(',', $atts['categories']);
     205               
     206                        foreach ($ids as $id) {
     207                            // Appel HTTP API
     208                            $link       = $prestashop_url . '/api/products/?filter[id_category_default]=[' . $id . ']&ws_key=' . $webservice_key . '&output_format=JSON';
     209                            $response   = wp_remote_get( $link );
     210                            $body       = wp_remote_retrieve_body( $response );
     211                            $http_code  = wp_remote_retrieve_response_code( $response );
     212               
     213                            if ($http_code == '200') {
     214                                // Produit (format JSON > Array)
     215                                $result = json_decode($body);
     216   
     217                                foreach ($result->products as $element) {
     218                                    if (array_key_exists($element->id, $_products)) {
     219                                        $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';
     220                                    }
     221                                }
     222                            }
     223                        }
     224                    }
     225                    else {
     226                        // Fonctions de traitement du tableau
     227                        array_splice($_products, $limit);
     228
     229                        // Récupération produit
     230                        foreach ($_products as $element) {
     231                            $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';
     232                        }
     233                    }
     234
     235                    // Fonctions de traitement du tableau
     236                    array_splice($url, $limit);
     237                }
     238            }
     239            // 1 produit
     240            else if (isset($atts['product'])) {
     241                $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';
     242            }
     243            // Plusieurs produits
     244            else if (isset($atts['products'])) {
     245                $ids = explode(',', $atts['products']);
     246               
     247                foreach ($ids as $id) {
     248                    $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';
    185249                }
    186250            }
     
    230294                foreach($wpml_languages as $languages) {
    231295                    if ($languages['active']) {
    232                         $langue_actuel  = $languages['language_code'];//default_locale'];
     296                        $langue_actuel = $languages['language_code'];//default_locale'];
    233297                        break;
    234298                    }
     
    260324            // Si l'utilisateur force la langue
    261325            if (isset($atts['language'])) {
    262                 $langue_actuel  = $atts['language'];
     326                $langue_actuel = $atts['language'];
    263327                $link           = $prestashop_url . '/api/languages/?display=[id,iso_code]&ws_key=' . $webservice_key . '&output_format=JSON';
    264328                $response       = wp_remote_get( $link );
     
    331395                        }
    332396                       
     397                        // URL par défaut (si aucune redirection n'est trouvée)
     398                        if (empty($product->url_rewrite) || !isset($product->url_rewrite)) {
     399                            if (is_array($product->product->link_rewrite) && count($product->product->link_rewrite) > 0) {
     400                                $link_rewrite = $product->product->link_rewrite[0]->value;
     401                            }
     402                            else {
     403                                $link_rewrite = $product->product->link_rewrite;
     404                            }
     405                           
     406                            $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';
     407                        }
     408                       
    333409                        // Gestion de la langue par défaut
    334410                        $id_lang = 1;
    335411                                               
    336                         // Gestion de la langue avec Polylang OU WPML
     412                        // Gestion de la langue avec Polylang
    337413                        if (isset($prest_languages) and !empty($prest_languages) and is_array($prest_languages->languages) and count($prest_languages->languages) > 0) {
    338414                            foreach($prest_languages->languages as $key => $prest_language) {
     
    359435                            $product->product->url_rewrite          = $product->product->url_rewrite[$keyToSave]->value;
    360436                            // V1.1.19 - END
    361                         }
    362                        
    363                         // URL par défaut (si aucune redirection n'est trouvée)
    364                         if (empty($product->url_rewrite) || !isset($product->url_rewrite) || isset($atts['language'])) { // !empty($product->product->link_rewrite)
    365                             if (is_array($product->product->link_rewrite) && count($product->product->link_rewrite) > 0) {
    366                                 $link_rewrite = $product->product->link_rewrite[0]->value;
    367                             }
    368                             else {
    369                                 $link_rewrite = $product->product->link_rewrite;
    370                             }
    371                            
    372                             $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';
    373437                        }
    374438                       
  • presta-products/trunk/readme.txt

    r3002286 r3032206  
    55Requires at least: 4.7
    66Requires PHP: 5.6
    7 Tested up to: 6.4
     7Tested up to: 6.4.3
    88Stable tag: 1.1.20
    99License: GPLv2 or later
     
    6464== Changelog ==
    6565
    66 = 1.1.20 = (27/11/2023)
    67 * Fixed: Gestion du lien du produit dans les différentes langues (avec WPML)
     66= 1.1.20 = (06/02/2024)
     67* Testée jusqu’à la version 6.4.3 de WordPress
     68* Fixed: Gestion de l'option bestsellers combiné à un autre parmi la liste suivante : product, products, category, categories
    6869
    6970= 1.1.19 = (15/11/2023)
Note: See TracChangeset for help on using the changeset viewer.