aztecmedia Posted January 14, 2013 Share Posted January 14, 2013 (edited) Hi, I'm using a number of different versions of Prestashop for different clients and there seems to be a common issue to all of them. One site is using 1.4.2 another 1.5.2. All the products on the website are set-up with a base price of £0.00 and then the combinations increase this base price. For example a product may come in 3 sizes, the Small will increase this base price by £10.00, Medium by £12.00 and Large by £14.00. Now when I'm viewing a category there my be 20 products and the number of products per page is set to 10. When I view the first page of ten items with the sort set to "lowest price first" this works fine. However when I move on to the second page of products it has this page starting at a lower price than the previous page finished on... For example: Page 1 Product 1 - £10.00 Product 2 - £15.00 Product 3 - £18.00 Page 2 Product 4 - £14.00 Product 5 - £16.00 Product 6 - £22.00 The sort on the Prestashop demo here - http://demo-store.pr...en/10-furniture - works fine, but I'm assuming that is because each product has a base product. I guess the issue must be that all the products have a base price of £0.00, but xan anyone suggest a fix? Many thanks, Oliver Edited January 14, 2013 by aztecmedia (see edit history) 1 Link to comment Share on other sites More sharing options...
clsoserbkk Posted January 20, 2013 Share Posted January 20, 2013 +1 Same in here. I need to increase my "products per page" value to 64. This workaround isnt nice cause this is increasing load time and I want to add product. Prestashop experts any thoughts... Thanks Link to comment Share on other sites More sharing options...
clsoserbkk Posted January 22, 2013 Share Posted January 22, 2013 Anyone can help please? Link to comment Share on other sites More sharing options...
clsoserbkk Posted January 23, 2013 Share Posted January 23, 2013 Help needed Link to comment Share on other sites More sharing options...
west28 Posted January 26, 2013 Share Posted January 26, 2013 hey. I modified the line in product-sort.tpl. Work's fine <form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}"> <p class="select"> <label for="selectPrductSort">{l s='Sort by'}</label> <select id="selectPrductSort" onchange="document.location.href = $(this).val();"> <option value="{$orderbydefault|escape:'htmlall':'UTF-8'}:{$orderwaydefault|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'price', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Price: lowest first'}</option> <option value="{$link->addSortDetails($request, 'price', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Price: highest first'}</option> {/if} <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Name: A to Z'}</option> <option value="{$link->addSortDetails($request, 'name', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product Name: Z to A'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'quantity', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'quantity' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='In-stock first'}</option> {/if} </select> </p> </form> Regards from Poland 3 Link to comment Share on other sites More sharing options...
mohamadeffazuan Posted January 29, 2013 Share Posted January 29, 2013 Hi west28, I'm also looking the solution for this problem, thanks for your advice. I've tried your code and it's work. Thank you so much. Regards from Malaysia Link to comment Share on other sites More sharing options...
aztecmedia Posted January 29, 2013 Author Share Posted January 29, 2013 Hi, Thank you for the code, but unfortunately it hasn't made any difference for me. If you go here: http://www.ocmis.com/15-sprinklers You can then see an example of the problem I have. The products are sorted by price (ascending) by default. If you click onto Page 2 of the products, you'll see that it starts with cheaper products than the first page ended with. It seems the filter only works per page rather than taking all the products, sorting them and then splitting them over the pages. Thanks in advance, Oliver Link to comment Share on other sites More sharing options...
clsoserbkk Posted January 29, 2013 Share Posted January 29, 2013 +1 For me. This script has no effect as well. Link to comment Share on other sites More sharing options...
joseantgv Posted July 30, 2013 Share Posted July 30, 2013 (edited) The problem is that the query get the product price without taking into consideration the impact of the combinations. If you have these products: Price Product 1 - 10$ | Combination impact 0$ Price Product 2 - 12$ | Combination impact 0$ Price Product 3 - 0$ | Combination impact 15$ Price Product 4 - 0$ | Combination impact 1$ The query order would be: Product 3 - 0$ Product 4 - 0$ Product 1 - 10$ Product 2 - 20$ Before showing products, it calls a function to get the real price and that's why you get this order supposing you have a pagination of 3 products: Product 4 - 1$ Product 3 - 15$ Product 1 - 10$ ------------------- Product 2 - 12$ To solve this I modify the function getProducts in class Category. I delete the LIMIT clause to get all the products, then get the real price for the default combination for all products, order them and get the desired array slice: $sql .= ' ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay);//.' //LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n); if ($orderBy == 'orderprice') Tools::orderbyPrice($result, $orderWay); //Get array slice depending on number of products per page and the page where I am $result = array_slice($result, (((int)$p - 1) * (int)$n), (int)$n); if (!$result) return false; /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); This is not best solution in terms of performance, but I think it would be very difficult to query results with the correct price. Edited July 30, 2013 by joseantgv (see edit history) 1 Link to comment Share on other sites More sharing options...
lav3pa Posted January 11, 2014 Share Posted January 11, 2014 The problem is that the query get the product price without taking into consideration the impact of the combinations. If you have these products: Price Product 1 - 10$ | Combination impact 0$ Price Product 2 - 12$ | Combination impact 0$ Price Product 3 - 0$ | Combination impact 15$ Price Product 4 - 0$ | Combination impact 1$ The query order would be: Product 3 - 0$ Product 4 - 0$ Product 1 - 10$ Product 2 - 20$ Before showing products, it calls a function to get the real price and that's why you get this order supposing you have a pagination of 3 products: Product 4 - 1$ Product 3 - 15$ Product 1 - 10$ ------------------- Product 2 - 12$ To solve this I modify the function getProducts in class Category. I delete the LIMIT clause to get all the products, then get the real price for the default combination for all products, order them and get the desired array slice: $sql .= ' ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay);//.' //LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n); if ($orderBy == 'orderprice') Tools::orderbyPrice($result, $orderWay); //Get array slice depending on number of products per page and the page where I am $result = array_slice($result, (((int)$p - 1) * (int)$n), (int)$n); if (!$result) return false; /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); This is not best solution in terms of performance, but I think it would be very difficult to query results with the correct price. Hello, I am having the same problem. There are some topics about this problem but only you give an solution. I have Presta 1.5.6.1 and still not working. I check for classes/category.php but I didn't find the line's that you talk above. Can you help me with this, please. Link to comment Share on other sites More sharing options...
lav3pa Posted January 11, 2014 Share Posted January 11, 2014 Hello, I am having the same problem. There are some topics about this problem but only you give an solution. I have Presta 1.5.6.1 and still not working. I check for classes/category.php but I didn't find the line's that you talk above. Can you help me with this, please. I find those lines and replace them with your fix but still de sort by is for products from page not from all products Link to comment Share on other sites More sharing options...
lav3pa Posted January 11, 2014 Share Posted January 11, 2014 Actually seems that is woking but only for cateogryes page- for special products is still sorting by page not by all products. Please help me to resolve this issue. Link to comment Share on other sites More sharing options...
joseantgv Posted January 12, 2014 Share Posted January 12, 2014 Actually seems that is woking but only for cateogryes page- for special products is still sorting by page not by all products. Please help me to resolve this issue. This fix is only for category page. If you want this feature at Special products (you mean products with specific prices, right?) you have to do the same modification in function getPricesDrop of file classes/Product.php. Link to comment Share on other sites More sharing options...
lav3pa Posted January 13, 2014 Share Posted January 13, 2014 This fix is only for category page. If you want this feature at Special products (you mean products with specific prices, right?) you have to do the same modification in function getPricesDrop of file classes/Product.php. I want this on price-drop page. What function I need to modify? Link to comment Share on other sites More sharing options...
joseantgv Posted January 13, 2014 Share Posted January 13, 2014 I want this on price-drop page. What function I need to modify? Function getPricesDrop of file classes/Product.php Link to comment Share on other sites More sharing options...
lav3pa Posted January 13, 2014 Share Posted January 13, 2014 After some more test I found out that neither the category sort by price works. I was testing in a category with a small number of products and by coincidence the sorting was ok. With a bigger category : http://www.ssshoesss.ro/new/38-incaltaminte-barbati#/ the sorting is not ok. Please give me another suggestions. I check my other site and this problem is present there too. And I check with default theme also, so the theme is not the problem. Somebody announce this bug? Link to comment Share on other sites More sharing options...
joseantgv Posted January 13, 2014 Share Posted January 13, 2014 After some more test I found out that neither the category sort by price works. I was testing in a category with a small number of products and by coincidence the sorting was ok. With a bigger category : http://www.ssshoesss.ro/new/38-incaltaminte-barbati#/ the sorting is not ok. Please give me another suggestions. I check my other site and this problem is present there too. And I check with default theme also, so the theme is not the problem. Somebody announce this bug? I can't find the bug at http://www.ssshoesss.ro/new/38-incaltaminte-barbati sorting it by "Pret: ascendent". Could you upload a screenshot with the error? Link to comment Share on other sites More sharing options...
lav3pa Posted January 13, 2014 Share Posted January 13, 2014 I can't find the bug at http://www.ssshoesss.ro/new/38-incaltaminte-barbati sorting it by "Pret: ascendent". Could you upload a screenshot with the error? The last product from the first page result over sorting by price ( show 50 products per page) ascending has 161 lei price. An if you go on page 4 of this search you will se the first product has 99 lei price. Link to comment Share on other sites More sharing options...
joseantgv Posted January 13, 2014 Share Posted January 13, 2014 The problem is that the price that appear is because of a discount. It's not taken into account in this modification. Link to comment Share on other sites More sharing options...
lav3pa Posted January 13, 2014 Share Posted January 13, 2014 The problem is that the price that appear is because of a discount. It's not taken into account in this modification. And is there an way to change it? For this reason the sorting dosnt work for price-drop page, also? Link to comment Share on other sites More sharing options...
joseantgv Posted January 13, 2014 Share Posted January 13, 2014 And is there an way to change it? For this reason the sorting dosnt work for price-drop page, also? Sure, but it's not that easy because discounts can be subjected to different variables. For price drop page the sorting will be the same. Link to comment Share on other sites More sharing options...
lav3pa Posted January 14, 2014 Share Posted January 14, 2014 Sure, but it's not that easy because discounts can be subjected to different variables. For price drop page the sorting will be the same. And this was the way that this function was developed, or is an bug? On older version I saw that the sorting is working. Link to comment Share on other sites More sharing options...
joseantgv Posted January 14, 2014 Share Posted January 14, 2014 And this was the way that this function was developed, or is an bug? On older version I saw that the sorting is working. I think that it was developed this way, but if you consider you can open an issue at http://forge.prestashop.com/. Link to comment Share on other sites More sharing options...
lav3pa Posted January 15, 2014 Share Posted January 15, 2014 I think that it was developed this way, but if you consider you can open an issue at http://forge.prestashop.com/. I open this http://forge.prestashop.com/browse/PSCFV-11504 for this problem. Link to comment Share on other sites More sharing options...
w3bsolutions Posted March 17, 2014 Share Posted March 17, 2014 Same issue here using 1.5.6.2. Most of my products have base price 0 and then the price is set on the combinations. Link to comment Share on other sites More sharing options...
savvato Posted April 23, 2015 Share Posted April 23, 2015 (edited) my solution In classes/Category.php in function getProducts find product_shop.price AS orderprice and replase IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price full function for ovverride public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) { if (!$context) $context = Context::getContext(); if ($check_access && !$this->checkAccess($context->customer->id)) return false; $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by)) $order_by = 'position'; else /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); if (empty($order_way)) $order_way = 'ASC'; $order_by_prefix = false; if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; elseif ($order_by == 'name') $order_by_prefix = 'pl'; elseif ($order_by == 'manufacturer' || $order_by == 'manufacturer_name') { $order_by_prefix = 'm'; $order_by = 'name'; } elseif ($order_by == 'position') $order_by_prefix = 'cp'; if ($order_by == 'price') $order_by = 'orderprice'; if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $id_supplier = (int)Tools::getValue('id_supplier'); /* Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)$this->id. ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.id_product_attribute) id_product_attribute, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, MAX(il.`legend`) as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) : Product::sqlStock('p', 'product', false, Context::getContext()->shop)).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') .' GROUP BY product_shop.id_product'; if ($random === true) $sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products; else $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; //d($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($order_by == 'orderprice') Tools::orderbyPrice($result, $order_way); if (!$result) return array(); //d($result); /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); } for manufacturers override this function public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null) { if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by) || $order_by == 'position') $order_by = 'name'; if (empty($order_way)) $order_way = 'ASC'; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'; /* Return only the number of products */ if ($get_total) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE p.id_manufacturer = '.(int)$id_manufacturer .($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' WHERE cg.`id_group` '.$sql_groups.' )'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return (int)count($result); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $alias = ''; if ($order_by == 'price') { $order_by = 'orderprice'; $alias = '';} elseif ($order_by == 'name') $alias = 'pl.'; elseif ($order_by == 'manufacturer_name') { $order_by = 'name'; $alias = 'm.'; } elseif ($order_by == 'quantity') $alias = 'stock.'; else $alias = 'p.'; $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice ' .(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute , pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( product_shop.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new'.(Combination::isFeatureActive() ? ',MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .' FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') : '').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) '.Product::sqlStock('p', 0); if (Group::isFeatureActive() || $active_category) { $sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)'; if (Group::isFeatureActive()) $sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.$sql_groups.')'; if ($active_category) $sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1'; } $sql .= ' WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.' '.($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' GROUP BY product_shop.id_product ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; if ($order_by == 'price') Tools::orderbyPrice($result, $order_way); return Product::getProductsProperties($id_lang, $result); } regards from Ukraine. Edited April 23, 2015 by savvato (see edit history) 1 Link to comment Share on other sites More sharing options...
kzwp Posted April 25, 2015 Share Posted April 25, 2015 my solution In classes/Category.php in function getProducts find product_shop.price AS orderprice and replase IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price full function for ovverride public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) { if (!$context) $context = Context::getContext(); if ($check_access && !$this->checkAccess($context->customer->id)) return false; $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by)) $order_by = 'position'; else /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); if (empty($order_way)) $order_way = 'ASC'; $order_by_prefix = false; if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; elseif ($order_by == 'name') $order_by_prefix = 'pl'; elseif ($order_by == 'manufacturer' || $order_by == 'manufacturer_name') { $order_by_prefix = 'm'; $order_by = 'name'; } elseif ($order_by == 'position') $order_by_prefix = 'cp'; if ($order_by == 'price') $order_by = 'orderprice'; if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $id_supplier = (int)Tools::getValue('id_supplier'); /* Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)$this->id. ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.id_product_attribute) id_product_attribute, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, MAX(il.`legend`) as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) : Product::sqlStock('p', 'product', false, Context::getContext()->shop)).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') .' GROUP BY product_shop.id_product'; if ($random === true) $sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products; else $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; //d($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($order_by == 'orderprice') Tools::orderbyPrice($result, $order_way); if (!$result) return array(); //d($result); /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); } for manufacturers override this function public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null) { if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by) || $order_by == 'position') $order_by = 'name'; if (empty($order_way)) $order_way = 'ASC'; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'; /* Return only the number of products */ if ($get_total) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE p.id_manufacturer = '.(int)$id_manufacturer .($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' WHERE cg.`id_group` '.$sql_groups.' )'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return (int)count($result); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $alias = ''; if ($order_by == 'price') { $order_by = 'orderprice'; $alias = '';} elseif ($order_by == 'name') $alias = 'pl.'; elseif ($order_by == 'manufacturer_name') { $order_by = 'name'; $alias = 'm.'; } elseif ($order_by == 'quantity') $alias = 'stock.'; else $alias = 'p.'; $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice ' .(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute , pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( product_shop.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new'.(Combination::isFeatureActive() ? ',MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .' FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') : '').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) '.Product::sqlStock('p', 0); if (Group::isFeatureActive() || $active_category) { $sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)'; if (Group::isFeatureActive()) $sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.$sql_groups.')'; if ($active_category) $sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1'; } $sql .= ' WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.' '.($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' GROUP BY product_shop.id_product ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; if ($order_by == 'price') Tools::orderbyPrice($result, $order_way); return Product::getProductsProperties($id_lang, $result); } regards from Ukraine. Thanks, it works in my shop Link to comment Share on other sites More sharing options...
mlarino Posted May 19, 2015 Share Posted May 19, 2015 my solution In classes/Category.php in function getProducts find product_shop.price AS orderprice and replase IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price full function for ovverride public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) { if (!$context) $context = Context::getContext(); if ($check_access && !$this->checkAccess($context->customer->id)) return false; $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by)) $order_by = 'position'; else /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); if (empty($order_way)) $order_way = 'ASC'; $order_by_prefix = false; if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; elseif ($order_by == 'name') $order_by_prefix = 'pl'; elseif ($order_by == 'manufacturer' || $order_by == 'manufacturer_name') { $order_by_prefix = 'm'; $order_by = 'name'; } elseif ($order_by == 'position') $order_by_prefix = 'cp'; if ($order_by == 'price') $order_by = 'orderprice'; if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $id_supplier = (int)Tools::getValue('id_supplier'); /* Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)$this->id. ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.id_product_attribute) id_product_attribute, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, MAX(il.`legend`) as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) : Product::sqlStock('p', 'product', false, Context::getContext()->shop)).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') .' GROUP BY product_shop.id_product'; if ($random === true) $sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products; else $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; //d($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($order_by == 'orderprice') Tools::orderbyPrice($result, $order_way); if (!$result) return array(); //d($result); /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); } for manufacturers override this function public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null) { if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by) || $order_by == 'position') $order_by = 'name'; if (empty($order_way)) $order_way = 'ASC'; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'; /* Return only the number of products */ if ($get_total) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE p.id_manufacturer = '.(int)$id_manufacturer .($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' WHERE cg.`id_group` '.$sql_groups.' )'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return (int)count($result); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $alias = ''; if ($order_by == 'price') { $order_by = 'orderprice'; $alias = '';} elseif ($order_by == 'name') $alias = 'pl.'; elseif ($order_by == 'manufacturer_name') { $order_by = 'name'; $alias = 'm.'; } elseif ($order_by == 'quantity') $alias = 'stock.'; else $alias = 'p.'; $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice ' .(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute , pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( product_shop.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new'.(Combination::isFeatureActive() ? ',MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .' FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') : '').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) '.Product::sqlStock('p', 0); if (Group::isFeatureActive() || $active_category) { $sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)'; if (Group::isFeatureActive()) $sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.$sql_groups.')'; if ($active_category) $sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1'; } $sql .= ' WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.' '.($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' GROUP BY product_shop.id_product ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; if ($order_by == 'price') Tools::orderbyPrice($result, $order_way); return Product::getProductsProperties($id_lang, $result); } regards from Ukraine. Hello Sawato! I have been searching for days for a solution to this, and you are the only that shared a solution. I made the changes you suggested, but still doesnt work. I have all products at 0€, and are the variations that have the price, not sure if there is anything else I need to do to make this work. Thanks! Link to comment Share on other sites More sharing options...
mlarino Posted May 31, 2015 Share Posted May 31, 2015 Could anyone help me with this sorting problem? PRestashop sorts by base price, But ignores prices from product variations. Thanks! Link to comment Share on other sites More sharing options...
kzwp Posted July 30, 2015 Share Posted July 30, 2015 my solution In classes/Category.php in function getProducts find product_shop.price AS orderprice and replase IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price full function for ovverride public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) { if (!$context) $context = Context::getContext(); if ($check_access && !$this->checkAccess($context->customer->id)) return false; $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by)) $order_by = 'position'; else /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); if (empty($order_way)) $order_way = 'ASC'; $order_by_prefix = false; if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; elseif ($order_by == 'name') $order_by_prefix = 'pl'; elseif ($order_by == 'manufacturer' || $order_by == 'manufacturer_name') { $order_by_prefix = 'm'; $order_by = 'name'; } elseif ($order_by == 'position') $order_by_prefix = 'cp'; if ($order_by == 'price') $order_by = 'orderprice'; if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $id_supplier = (int)Tools::getValue('id_supplier'); /* Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)$this->id. ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.id_product_attribute) id_product_attribute, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, MAX(il.`legend`) as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS price FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) : Product::sqlStock('p', 'product', false, Context::getContext()->shop)).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') .' GROUP BY product_shop.id_product'; if ($random === true) $sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products; else $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; //d($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($order_by == 'orderprice') Tools::orderbyPrice($result, $order_way); if (!$result) return array(); //d($result); /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); } for manufacturers override this function public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null) { if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if ($p < 1) $p = 1; if (empty($order_by) || $order_by == 'position') $order_by = 'name'; if (empty($order_way)) $order_way = 'ASC'; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'; /* Return only the number of products */ if ($get_total) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE p.id_manufacturer = '.(int)$id_manufacturer .($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' WHERE cg.`id_group` '.$sql_groups.' )'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return (int)count($result); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $alias = ''; if ($order_by == 'price') { $order_by = 'orderprice'; $alias = '';} elseif ($order_by == 'name') $alias = 'pl.'; elseif ($order_by == 'manufacturer_name') { $order_by = 'name'; $alias = 'm.'; } elseif ($order_by == 'quantity') $alias = 'stock.'; else $alias = 'p.'; $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, IFNULL(MIN(product_attribute_shop.price),product_shop.price) AS orderprice ' .(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute , pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( product_shop.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new'.(Combination::isFeatureActive() ? ',MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') .' FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') : '').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) '.Product::sqlStock('p', 0); if (Group::isFeatureActive() || $active_category) { $sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)'; if (Group::isFeatureActive()) $sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.$sql_groups.')'; if ($active_category) $sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1'; } $sql .= ' WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.' '.($active ? ' AND product_shop.`active` = 1' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' GROUP BY product_shop.id_product ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; if ($order_by == 'price') Tools::orderbyPrice($result, $order_way); return Product::getProductsProperties($id_lang, $result); } regards from Ukraine. When the blocklayered module is enabled it does not work... Link to comment Share on other sites More sharing options...
ThunderOver Posted May 4, 2016 Share Posted May 4, 2016 Hi guys, sorry if I take this old thread, I have pretty much the same problem with prestashop 1.6.1 there is a solution? Link to comment Share on other sites More sharing options...
Artemis909 Posted September 11, 2017 Share Posted September 11, 2017 (edited) joseantgv's solution working also in Presta 1.7 but changes must be done in module/ps_facedsearch/ps_facedsearch.php in function getProductByFilters() Edited September 12, 2017 by Artemis909 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts