Jump to content

Hide specific products or products from a category from homepage


axafarm

Recommended Posts

Hello,

 

I want to hide specific products or products from a specific category from homepage. I have sections like new products, best seller, or featured products on homepage and I want to hide the products from a category to appear in those sections. I know how to identify the products from that category by reference, all the products from that category starts with the same reference. I identify the products with this code:  {if substr($product.reference, 0, 1) =='W'}, the code works because I used it to set an default image to products with 'W' reference. Now I don't know how to make it work so I can hide products from homepage that starts with reference 'w' for example. I want to hide them only from homepage. Please help me!

 

Thank you!

Link to comment
Share on other sites

In category.php, getProducts method, you can add this condition to the sql that retrieves products. Make sure it's in the WHERE part
Replace 2 with the homepage id.

'.($this->id == 2 ? 'AND p.id_reference !="whatever"' : "").'

You can obviously add different conditions to check what part of the reference to check

Link to comment
Share on other sites

So basically I have to add here in this code 

if ($getTotal) {
            $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' : '') .
                ($idSupplier ? 'AND p.id_supplier = ' . (int) $idSupplier : '');

            return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
        }

I'm using prestashop 1.7.5, my homepage doesn't have an ID in link, if there is an ID for homepage I really don't know how to find it..

Link to comment
Share on other sites

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...