Code suggestion
-
Hi, I have some suggestion to give the plugin more performance and reduce the number of queries used.
In some cases, the original code doesn’t work at all, if your product id start from a number greater than 30.The file is wp-prestashop-cs.php
As you can see I put here only an example for the first case, random product without category.
First of all, the get_option calls doesn’t need to be inside the for cycle.
Than the method to get a random product can fail. This one choose a random product among all not only the first 30.
Many queries have been joined in just one.
This modification can be easyly applied to the single caregory case.
Hope this can help!
Diego
$retval = ''; //get size of image, default language, product selection type and category $image_size = get_option('wppscs_prod_img_size'); //image size $language = get_option('wppscs_ps_language');; //Prestashop language $category = get_option('wppscs_prod_category');;//select Prestashop category $store_url = get_option('wppscs_store_url'); $image_folder = get_option('wppscs_prod_img_folder'); if ($prod_selection == "random"){ //search whole database for ($i=0; $i<$product_cnt; $i++) { // get a valid random product $prodtotal=$PrestaShopdb->get_var("SELECT COUNT(*) FROM ps_product WHERE active=1"); $limitstart=mt_rand(0,$prodtotal-1); //Get product image, name and URL $product_array = $PrestaShopdb->get_results('SELECT pl.name, i.id_image, p.id_product FROM ps_product p LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.$language.') LEFT JOIN ps_image i ON (i.id_product = p.id_product AND i.cover = 1) LEFT JOIN ps_image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.$language.') WHERE p.active = 1 limit '.$limitstart.',1',ARRAY_A); $id_image=$product_array[0]['id_image']; $product_name=$product_array[0]['name']; $product_id=$product_array[0]['id_product'];
- The topic ‘Code suggestion’ is closed to new replies.