Jump to content

[SOLVED] Need help Editing New products Block PLS


Arif

Recommended Posts

Hey, Any body I want to edit New products Block so that certain products from certain categories dont show up in it. for example I have a category called Used Items @ my shop, I want that If I add a new product to it from the back end that doesnt show up in the new products list........ I AM DESPERATE ANY HELP WILL BE APPRECIATED :)

Link to comment
Share on other sites

Topics split and merged

You'll need to modify the getNewProducts function in classes/Product.php and add a WHERE clause to the queries to hide certain categories.

For example, change line 992 from:

WHERE `active` = 1



to:

WHERE `active` = 1 AND `id_category_default` != 2



and line 1007 from:

WHERE p.`active` = 1



to:

WHERE p.`active` = 1 AND p.`id_category_default` != 2



where 2 is the category that you want hidden from the new products block. For this code to work, you must make the default category of the product the one you want it hidden from.

  • Like 2
Link to comment
Share on other sites

Hey rocky,


What if I need to make the following changes to the Top Sellers Block...


I want that when a user is in laptops category only laptops show up in best sellers
when hes in home over all best sellers show
when hes in cell phones , best sellers from cell phones show...


again your help will be greatly appreciated :)


Arif

Link to comment
Share on other sites

This is not an easy change to a template. It requires modifications to a core function. You'll need to change the getBestSalesLight function in classes/ProductSale.php to:

static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, $id_category = 0)
{
    global $link, $cookie;

   if ($pageNumber < 0) $pageNumber = 0;
   if ($nbProducts < 1) $nbProducts = 10;

   $result = Db::getInstance()->ExecuteS('
   SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, 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` = '.intval($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` = '.intval($id_lang).')
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.intval($id_lang).')
   WHERE p.`active` = 1' . ($id_category == 0 ? '' : ' AND p.`id_category_default` = '.$id_category) . '
   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` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
   )
   GROUP BY p.`id_product`
   ORDER BY sales DESC
   LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts));
   if (!$result)
       return $result;

   foreach ($result AS &$row)
   {
        $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
        $row['id_image'] = Product::defineProductImage($row);
   }
   return $result;
}



then you can change line 35 of modules/blockbestsellers.php to:

$bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $_GET['id_category']);



I haven't tested it, but it should work, assuming you have the default category of the products set to the appropriate subcategory.

Link to comment
Share on other sites

  • 6 months later...

Hey rocky,

Thanks for that code from your first post! Everything seems to be working fine... I just have a quick question regarding the `id_category_default` field.

From my understanding (which isn't great) I though id_category_default is the default category the product was created in... which works fine in most cases, but what happens if a product is moved to a different category? Will the above query change work for those products?

My understanding was that even after the product is moved the product still retains its id_category_default value, but changes id_category value to the new category it is moved to... if this is the case, is there a way to change the above query to account for these details? We are always moving things around, and a lot got moved around when we first setup the shop... so we want to make sure this works for all the products for specific category regardless of where they were originally created in.

Thanks!

Link to comment
Share on other sites

No, it won't. You must be careful to change the default category whenever move a product from one category to another. You'd need to write a more complicated SQL query to get all the categories that the product is in. Using just the default category simplifies the query.

Link to comment
Share on other sites

  • 5 months later...

The only solution I can think of is to edit the getBestSales() and getBestSalesLight() functions in classes/Product.php and change:

WHERE p.`active` = 1



to:

WHERE p.`active` = 1 AND p.`id_product` != 2



Change 2 to the ID of the product you want to exclude. Add more AND clauses as necessary.

Link to comment
Share on other sites

The only solution I can think of is to edit the getBestSales() and getBestSalesLight() functions in classes/Product.php and change:

WHERE p.`active` = 1



to:

WHERE p.`active` = 1 AND p.`id_product` != 2



Change 2 to the ID of the product you want to exclude. Add more AND clauses as necessary.



Doesn't work in me. What I did is I delete this line:


AND p.`date_add` > DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)



and change the line in new-products.php

from

'products' => Product::getNewProducts(intval($cookie->id_lang), intval($p) - 1, intval($n), false, $orderBy, $orderWay),



to

'products' => Product::getNewProducts(intval($cookie->id_lang), intval($p) - 1, intval($n)),



check the live site here :

http://5angelsaccessories.com

Link to comment
Share on other sites

  • 7 months later...

Does anyone have any insight in how to accomplish this in Ver 1.4? I have a category of products I want to be visible only to one group of customers. Have managed to configure so that category only appears in category block if a customer assigned to that group logs in. BUT some of these products are popping up in the New Products block before login so are visible to anyone (and I bet they would show up in the Top Seller block if they sold well -- possibly elsewhere?) Anyway, I tried to implement the changes suggested in this thread, but line numbers are different in product.php. Found where I thought I should change the where clauses, but got a 500 error, so I guess I was wrong.

 

So I need some guidance on how to make sure this category and all products in it never appear to anyone other than the customers assigned to one specific group (in Ver 1.4.4.1). Thanks!

Link to comment
Share on other sites

  • 1 year later...

Topics split and merged

 

You'll need to modify the getNewProducts function in classes/Product.php and add a WHERE clause to the queries to hide certain categories.

 

For example, change line 992 from:

 

WHERE `active` = 1

 

to:

 

WHERE `active` = 1 AND `id_category_default` != 2

 

and line 1007 from:

 

WHERE p.`active` = 1

 

to:

 

WHERE p.`active` = 1 AND p.`id_category_default` != 2

 

where 2 is the category that you want hidden from the new products block. For this code to work, you must make the default category of the product the one you want it hidden from.

 

 

 

I am not able to find the particular code in my prestashop 1.5.4.How to do this in prestashop 1.5.4???

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

HI kkmixs,

 

On line 2019, you change

 

$sql->where('product_shop.`active` = 1');

 

to

 

$sql->where('product_shop.`active` = 1 AND product_shop.`id_category_default` != 12');

 

where 12 is the cat id

 

 

How to add more than one category?

 

by the way thanks for the help

Link to comment
Share on other sites

  • 8 months later...

This is not an easy change to a template. It requires modifications to a core function. You'll need to change the getBestSalesLight function in classes/ProductSale.php to:

 

static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, $id_category = 0){     global $link, $cookie;             if ($pageNumber < 0) $pageNumber = 0;    if ($nbProducts < 1) $nbProducts = 10;            $result = Db::getInstance()->ExecuteS('    SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, 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` = '.intval($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` = '.intval($id_lang).')    LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.intval($id_lang).')    WHERE p.`active` = 1' . ($id_category == 0 ? '' : ' AND p.`id_category_default` = '.$id_category) . '    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` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'    )    GROUP BY p.`id_product`    ORDER BY sales DESC    LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts));    if (!$result)        return $result;            foreach ($result AS &$row)    {         $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);         $row['id_image'] = Product::defineProductImage($row);    }    return $result;}

then you can change line 35 of modules/blockbestsellers.php to:

 

$bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5, $_GET['id_category']);

I haven't tested it, but it should work, assuming you have the default category of the products set to the appropriate subcategory.

 

 

Hi Rocky, 

 

Any chance you can guide me to apply this on my store running on 1.5.6.2 ?

 

Thanks.

Link to comment
Share on other sites

  • 11 months later...
  • 7 months later...

This was my solution for 1.6.0.14 was this one:

 

I created a new function in classes/productSale.php

static public function getBestSalesLightCat ($id_lang, $pageNumber = 0, $nbProducts = 10, $id_category = 0) {
            global $link, $cookie;
            $context = Context::getContext();
            if ($pageNumber < 0) $pageNumber = 0;
            if ($nbProducts < 1) $nbProducts = 10;
            $sql = '
                    SELECT p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
                    MAX(image_shop.`id_image`) id_image, il.`legend`, ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
                    IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock,
                    product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'" as new,
                    product_shop.`on_sale`, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity
                    FROM `'._DB_PREFIX_.'product_sale` ps
                    LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
                    '.Shop::addSqlAssociation('product', 'p').'
                    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).'
                    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_.'category_lang` cl
ON cl.`id_category` = product_shop.`id_category_default`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl');
            
                    if (Group::isFeatureActive())
                    {
                        $groups = FrontController::getCurrentCustomerGroups();
                        $sql .= '
                                JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
                                JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').')';
                    }
                    
                    $sql.= '
                            WHERE p.`active` = 1' . ($id_category == 0 ? '' : ' AND p.`id_category_default` = '.$id_category) . '
                            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` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group
                                                FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').')
                                                GROUP BY p.`id_product`
                                                ORDER BY sales DESC
                                                LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts);
            if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
                    return false;

            return Product::getProductsProperties($id_lang, $result);
        }

and then in the call function of blockbestsellers.php:

 

protected function getBestSellers($params)
{
if (Configuration::get('PS_CATALOG_MODE'))
return false;

                $id_category = 0;
                if (isset($_GET['id_category']) AND intval($_GET['id_category']) > 0) {
                    $category = new Category(intval($_GET['id_category']), intval($params['cookie']->id_lang));
                    if (Validate::isLoadedObject($category)) {
                        $id_category = intval($_GET['id_category']);
                    }
                if (!($result = ProductSale::getBestSalesLightCat((int)$params['cookie']->id_lang, 0, 5, $id_category)))
return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false);    
                }
                else {
                    if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, (int)Configuration::get('PS_BLOCK_BESTSELLERS_TO_DISPLAY'))))
return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false);
                }

$currency = new Currency($params['cookie']->id_currency);
$usetax = (Product::getTaxCalculationMethod((int)$this->context->customer->id) != PS_TAX_EXC);
foreach ($result as &$row)
$row['price'] = Tools::displayPrice(Product::getPriceStatic((int)$row['id_product'], $usetax), $currency);

return $result;
}

which will show you category bestsellers if you are inside a category with products that have that default category or if you are outside category pages will show you the normal result hole shop bestsales

Good Luck


I'm trying to get the childrens inside that category also, for example:

 

If I'm on category bikes
i would like that the module shows also the products with de default category in Bikes > Mountain bikes for example

 

If anyone have the answer plz, if get it I would post in here.

 

 

reggards
 

Edited by Aioras (see edit history)
  • Like 2
Link to comment
Share on other sites

Got it, I modified the function with One I saw on another post, this one will show every category the product is in, and not only the default one:

//Created to show bestsellers products on each category @Cn
        static public function getBestSalesLightCat ($id_lang, $page_number = 0, $nb_products = 10, $id_category = 0, Context $context = null) {
            if (!$context)
                    $context = Context::getContext();
            if ($page_number < 0) $page_number = 0;
            if ($nb_products < 1) $nb_products = 10;

            $sql_groups = '';
            if (Group::isFeatureActive())
            {
                    $groups = FrontController::getCurrentCustomerGroups();
                    $sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
            }
            //Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
            $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                SELECT cp.`id_product`
                FROM `'._DB_PREFIX_.'category_product` cp
                LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
                WHERE cg.`id_group` '.$sql_groups.' AND cp.id_category = '.(int)Tools::getValue('id_category'));

            $ids = array();
            foreach ($products as $product)
                    $ids[$product['id_product']] = 1;

            $ids = array_keys($ids);		
            sort($ids);
            $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';

            //Main query
            $sql = '
                SELECT
                        p.id_product,  MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
                        MAX(image_shop.`id_image`) id_image, il.`legend`,
                        ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
                        IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock,
                        product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'" as new, product_shop.`on_sale`
                FROM `'._DB_PREFIX_.'product_sale` ps
                LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
                '.Shop::addSqlAssociation('product', 'p').'
                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).'
                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_.'category_lang` cl
                        ON cl.`id_category` = product_shop.`id_category_default`
                        AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
                WHERE product_shop.`active` = 1
                AND p.`visibility` != \'none\'
                AND p.`id_product` IN ('.$ids.')
                GROUP BY product_shop.id_product
                ORDER BY sales DESC
                LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;

            if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
                    return false;

            return Product::getProductsProperties($id_lang, $result);
	}

got it from:

 

https://www.prestashop.com/forums/topic/244387-show-best-sellers-products-by-category-in-product-listing-page/?p=1936215

 

thank ynocquet !

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Got it, I modified the function with One I saw on another post, this one will show every category the product is in, and not only the default one:

//Created to show bestsellers products on each category @Cn
        static public function getBestSalesLightCat ($id_lang, $page_number = 0, $nb_products = 10, $id_category = 0, Context $context = null) {
            if (!$context)
                    $context = Context::getContext();
            if ($page_number < 0) $page_number = 0;
            if ($nb_products < 1) $nb_products = 10;

            $sql_groups = '';
            if (Group::isFeatureActive())
            {
                    $groups = FrontController::getCurrentCustomerGroups();
                    $sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
            }
            //Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
            $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                SELECT cp.`id_product`
                FROM `'._DB_PREFIX_.'category_product` cp
                LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
                WHERE cg.`id_group` '.$sql_groups.' AND cp.id_category = '.(int)Tools::getValue('id_category'));

            $ids = array();
            foreach ($products as $product)
                    $ids[$product['id_product']] = 1;

            $ids = array_keys($ids);		
            sort($ids);
            $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';

            //Main query
            $sql = '
                SELECT
                        p.id_product,  MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
                        MAX(image_shop.`id_image`) id_image, il.`legend`,
                        ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
                        IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock,
                        product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'" as new, product_shop.`on_sale`
                FROM `'._DB_PREFIX_.'product_sale` ps
                LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
                '.Shop::addSqlAssociation('product', 'p').'
                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).'
                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_.'category_lang` cl
                        ON cl.`id_category` = product_shop.`id_category_default`
                        AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
                WHERE product_shop.`active` = 1
                AND p.`visibility` != \'none\'
                AND p.`id_product` IN ('.$ids.')
                GROUP BY product_shop.id_product
                ORDER BY sales DESC
                LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;

            if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
                    return false;

            return Product::getProductsProperties($id_lang, $result);
	}

got it from:

 

https://www.prestashop.com/forums/topic/244387-show-best-sellers-products-by-category-in-product-listing-page/?p=1936215

 

thank ynocquet !

 

Works like a charm ! Thanks for the update on 1.6 @Aioras ! :)

Link to comment
Share on other sites

  • 2 months later...

Got it, I modified the function with One I saw on another post, this one will show every category the product is in, and not only the default one:

thank ynocquet !

I tried. And it works. But only in category page. This does not work on the product page.

Link to comment
Share on other sites

  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...