DARKF3D3 Posted January 12, 2014 Share Posted January 12, 2014 It's possible to do that? Someone know how to? Link to comment Share on other sites More sharing options...
limon994 Posted January 12, 2014 Share Posted January 12, 2014 Hello, Go to YOUR_SHOP_ROOT_DIR/modules/blockbestsellers/ And open blockbestsellers.php file in an editor now replace the following code public function hookRightColumn($params) { if (Configuration::get('PS_CATALOG_MODE')) return ; global $smarty; $currency = new Currency((int)($params['cookie']->id_currency)); $bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5); if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')) return; $best_sellers = array(); if($bestsellers) foreach ($bestsellers AS $bestseller) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic((int)($bestseller['id_product'])), $currency); $best_sellers[] = $bestseller; } $smarty->assign(array( 'best_sellers' => $best_sellers, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockbestsellers.tpl'); } with public function hookRightColumn($params) { if (Configuration::get('PS_CATALOG_MODE')) return ; global $smarty; $currency = new Currency((int)($params['cookie']->id_currency)); $bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5); if (!$bestsellers AND !Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY')) return; $best_sellers = array(); if($bestsellers) foreach ($bestsellers AS $bestseller) { $product = new Product($bestseller['id_product']); if($product->quantity>0) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStatic((int)($bestseller['id_product'])), $currency); $best_sellers[] = $bestseller; } } $smarty->assign(array( 'best_sellers' => $best_sellers, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockbestsellers.tpl'); } Now you can see only the products will be shown those are available(in stock) on your shop Thanks Link to comment Share on other sites More sharing options...
DARKF3D3 Posted January 12, 2014 Author Share Posted January 12, 2014 Hi limon, thanks for the help. I try your fix, it works, but it's not completely right. Because in this way for example with 10 products showed (4 of that not available), it remove the not available but it doesn't replace with the next available products. So it show only 6 products. I'm trying to show always 10, so if 1 is out of stock the module should take the 11th top seller. I hope you understand... Link to comment Share on other sites More sharing options...
limon994 Posted January 12, 2014 Share Posted January 12, 2014 Hello, Thanks for following my instruction. Yes I know that. What you are wanting to get that you have to override a class named ProductSale.php you can find this file at here YOUR_ROOT/classes/ProductSale.php Open this file in a text editor and replace the following code public static function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10) { global $link; if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; $groups = FrontController::getCurrentCustomerGroups(); $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`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_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.(int)$id_lang.') WHERE p.`active` = 1 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`) WHERE cg.`id_group` '.$sqlGroups.' ) ORDER BY sales DESC LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)($nbProducts)); if (!$result) return false; foreach ($result AS &$row) { $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']); $row['id_image'] = Product::defineProductImage($row, $id_lang); } return $result; } With public static function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10) { global $link; if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; $groups = FrontController::getCurrentCustomerGroups(); $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`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_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.(int)$id_lang.') WHERE p.`active` = 1 AND p.`quantity`>0 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`) WHERE cg.`id_group` '.$sqlGroups.' ) ORDER BY sales DESC LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)($nbProducts)); if (!$result) return false; foreach ($result AS &$row) { $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']); $row['id_image'] = Product::defineProductImage($row, $id_lang); } return $result; } Now You will see your result. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted January 12, 2014 Author Share Posted January 12, 2014 Pratically the only modify is the addition of "AND p.`quantity`>0" right? Link to comment Share on other sites More sharing options...
limon994 Posted January 12, 2014 Share Posted January 12, 2014 Hello, Yes I put the whole code for others if some one from non-technical person want to do the same issue to his/her shop. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted January 12, 2014 Author Share Posted January 12, 2014 (edited) Great it works. Thanks for the help! EDIT: Do you think there's a way to hide out of stock products also from the best seller page and not only from the module? Edited January 12, 2014 by DARKF3D3 (see edit history) Link to comment Share on other sites More sharing options...
Polyanyn Posted June 7, 2014 Share Posted June 7, 2014 Hello. How can I do it in Prestashop 1.6? Thank you for support. Link to comment Share on other sites More sharing options...
SAISSU Posted January 16, 2015 Share Posted January 16, 2015 (edited) "Hello. How can I do it in Prestashop 1.6? Thank you for support. "I'l like how to do too.thanks Edited January 16, 2015 by SAISSU (see edit history) Link to comment Share on other sites More sharing options...
karlangas77 Posted December 23, 2015 Share Posted December 23, 2015 Hello, I am trying to follow steps of this thread to filter best sellers by category but only for last month but not results. Any ideas ? thanks! (sorry for my crappy English) Link to comment Share on other sites More sharing options...
chosie Posted October 4, 2016 Share Posted October 4, 2016 Hello. How can I do it in Prestashop 1.6? Thank you for support. It is the same piece of code for prestashop 1.6.0.8. In classes/ProductSale.php, look for function getBestSalesLight and insert "AND stock.quantity > 0" in line 200. Remember to clear the cache in BO> Advance Parameters > Performance to see the changes reflected in home page. Link to comment Share on other sites More sharing options...
Liefzebraatje Posted October 10, 2016 Share Posted October 10, 2016 I tried to follow the instruction but i guesse its no more the same code. The code is changed in the module blockbestsellers. Can someone please provide me the new code where products which have quantity 0 are not displayed in this block Also for block new products and block specials. I think all 3 are quite simular... so if one is provided i will manage. (hope) Thanks Link to comment Share on other sites More sharing options...
yehanny Posted June 2, 2019 Share Posted June 2, 2019 I found a solution in prestashop 1.6 under Preferences / Products and DISABLE "Display unavailable product attributes on the product page" and also "Allow ordering of out-of-stock products" Now my site only shows products on stock only Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now