简体   繁体   中英

Show only products in stock of certain category Prestashop

I have a question about how to show only products that are in stock in a certain category in Prestashop. The other categories must show products out of stock and products in stock but this one only in stock.

I try to edit the function getProducts in Category.php and change the line:

WHERE product_shop. id_shop = '.(int)$context->shop->id.'

to:

WHERE stock. quantity > 0 AND product_shop. id_shop = '.(int)$context->shop->id.'

It doesn't worked and also I don't know where to put this query in order to only affects to this category.

Any idea about what I'm doing wrong?

Do you get an error? try to use "quantity" instead of "stock.quantity".

Also you should check id_category after $sql:

$sql = 'something';
if ($this->id == $targetCategoryId) { // $targetCategoryId can replace by configuration: Configuration::get('YOUR_CUSTOM_CATEGORY_ID')
    $sql .= 'AND WHERE quantity > 0';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM