Jump to content

New products block - products with 0 quantity


Recommended Posts

Hi,

I want to display in new products slider on main page and on new products page (new-products.tpl) only new products with quantity > 0.

My problem is that if i make a if statement in template to show only products with quantity higher than 0, on new products page i get 2 empty pages, and after them comes page with actual products. Looks like the products are taken from database before my if statement.

Is there a possibility to get from database only products with quantity > 0?

On category pages i want to see my sold out products, this should work only on new-prducts page and slider.

 

Prestashop version: 1.6.1.5

New products block version: 1.10.0

Link to comment
Share on other sites

Product quantities in PrestaShop are mapped to product combinations directly if there are any for a product.

 

If there are no combinations for your products then you can use the following query to fetch all the products with quantity > 0 

 



$sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.
'WHERE pl.`id_lang` = '.(int)$id_lang.' and p.quantity > 0';

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