Changeset 3183727
- Timestamp:
- 11/07/2024 10:42:39 AM (16 months ago)
- Location:
- presta-products/trunk
- Files:
-
- 1 added
- 5 edited
-
assets/javascript/ppgbo-admin.js (modified) (1 diff)
-
includes/admin-header.php (modified) (2 diffs)
-
includes/tabs/categories.php (added)
-
includes/tabs/examples.php (modified) (1 diff)
-
presta-products.php (modified) (19 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
presta-products/trunk/assets/javascript/ppgbo-admin.js
r2853481 r3183727 73 73 }); 74 74 }); 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 }); 75 87 }); -
presta-products/trunk/includes/admin-header.php
r2690016 r3183727 20 20 <a href="admin.php?page=presta-products&tab=cache" class="nav-tab <?php echo (($page == 'cache') ? 'nav-tab-active' : ''); ?>"><?php echo __( 'Cache', 'presta-products' ); ?></a> 21 21 <a href="admin.php?page=presta-products&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&tab=categories" class="nav-tab <?php echo (($page == 'categories') ? 'nav-tab-active' : ''); ?>"><?php echo __( 'Correspondances des catégories', 'presta-products' ); ?></a> 22 23 <?php 23 24 } … … 26 27 <a href="javascript:;" class="nav-tab" title="<?php echo __( 'Uniquement en version PREMIUM.', 'presta-products' ); ?>"><?php echo __( 'Cache (Option PREMIUM)', 'presta-products' ); ?></a> 27 28 <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> 28 30 <?php 29 31 } -
presta-products/trunk/includes/tabs/examples.php
r3002286 r3183727 29 29 </div> 30 30 <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 ?> 31 43 <div class="mt-3"> 32 44 <h5><?php echo __( 'Nombre de produits', 'presta-products'); ?></h5> -
presta-products/trunk/presta-products.php
r3116878 r3183727 4 4 * Plugin URI: https://www.guillaume-bouaud.fr/produit/presta-products-for-wordpress 5 5 * Description: Affichage des produits Prestashop sur le site internet généré par Wordpress. 6 * Version: 1. 1.276 * Version: 1.2.0 7 7 * Requires at least: 5.2 8 8 * Requires PHP: 7.2 … … 77 77 add_option( 'ppgbo_premium_key', '' ); 78 78 add_option( 'ppgbo_premium_userId', '' ); 79 // GBO - 1.2.0 80 add_option( 'ppgbo_use_categories', 0 ); 79 81 80 82 // Création de la table MYQSL … … 115 117 update_option( 'ppgbo_new_tab', '1' ); 116 118 update_option( 'ppgbo_use_cache', 0); 119 update_option( 'ppgbo_use_categories', 0); 117 120 } 118 121 // Si on est à moins de 5 connexions échouées vers le serveur … … 137 140 // Initialisation du tableau des produits 138 141 $products = array(); 139 142 140 143 // GBO - 1.1.21 141 144 // Gestion Bestsellers … … 183 186 } 184 187 } 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 } 185 208 else if (isset($atts['category'])) { 186 209 // Appel HTTP API … … 249 272 } 250 273 } 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 } 251 293 // Catégorie 252 294 else if (isset($atts['category'])) { … … 590 632 return $a->product->quantity < $b->product->quantity; 591 633 } 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' ); 592 653 593 654 // Fonction de changement des shortcodes … … 599 660 { 600 661 // 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'])) 602 663 { 603 664 return ""; … … 636 697 $arrows_carrousel = get_option( 'ppgbo_arrows_carrousel' ); 637 698 $dots_carrousel = get_option( 'ppgbo_dots_carrousel' ); 699 $use_categories = get_option( 'ppgbo_use_categories' ); 638 700 639 701 // Obfuscation forcée … … 792 854 add_filter('parent_file', 'presta_product_g_highlight_submenu'); 793 855 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 } 794 865 } 795 866 … … 849 920 'used_page' 850 921 ); 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 ); 851 930 } 852 931 } … … 858 937 // URL de récupération de la clé 859 938 $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 ); 860 944 861 945 // HTTP API 862 $response = wp_remote_get( $link );946 $response = wp_remote_get( $link, $args ); 863 947 $body = wp_remote_retrieve_body( $response ); 864 948 //$http_code = wp_remote_retrieve_response_code( $response ); … … 881 965 public function load_ppgbo_plugin_page() 882 966 { 967 global $wpdb; 968 883 969 // Sécurité : si on est sur le back office 884 970 if ( is_admin() ) { … … 989 1075 // Gestion du message d'information 990 1076 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 } 991 1113 } 992 1114 … … 1022 1144 $arrows_carrousel = get_option( 'ppgbo_arrows_carrousel' ); 1023 1145 $dots_carrousel = get_option( 'ppgbo_dots_carrousel' ); 1146 $use_categories = get_option( 'ppgbo_use_categories' ); 1024 1147 $counter_freemium = 5 - (get_option( 'ppgbo_counter_freemium' )); 1025 1148 $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'); 1027 1150 $list = $this->ppgbo_getListing(); 1028 1151 $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; 1029 1155 $product_template_1 = plugins_url( 'assets/images/product-template-1.png', __FILE__ ); 1030 1156 $product_template_2 = plugins_url( 'assets/images/product-template-2.png', __FILE__ ); … … 1041 1167 $dots_carrousel_2 = plugins_url( 'assets/images/circle.svg', __FILE__ ); 1042 1168 $script_cron = plugin_dir_path( __FILE__ ) . plugin_dir_path( 'scripts/cron/crontab-presta-products.php' ) . 'crontab-presta-products.php'; 1043 1169 1044 1170 // Gestion du message d'information 1045 1171 $message = get_option( 'ppgbo_message' ); … … 1055 1181 include 'includes/tabs/cache.php'; 1056 1182 include 'includes/tabs/used.php'; 1183 include 'includes/tabs/categories.php'; 1057 1184 } 1058 1185 … … 1159 1286 dbDelta($simple_sql); 1160 1287 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 ); 1167 1307 } 1168 1308 … … 1196 1336 } 1197 1337 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 1198 1353 // Vérification si la table existe 1199 1354 public function ppgbo_check_table_exists( $tablename ) { -
presta-products/trunk/readme.txt
r3116878 r3183727 6 6 Requires PHP: 5.6 7 7 Tested up to: 6.4.3 8 Stable tag: 1. 1.278 Stable tag: 1.2.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 63 63 64 64 == 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 65 70 66 71 = 1.1.27 = (12/07/2024)
Note: See TracChangeset
for help on using the changeset viewer.