从新产品列表中排除缺货产品 - Prestashop
问题描述:
我正在使用在主页中显示新增产品的模块。我需要自定义模块,以便该列表不包含销售的产品。换句话说,如果产品在被限制的天数之前缺货,则新产品已经结束,则不要在列表中显示该产品。从新产品列表中排除缺货产品 - Prestashop
我可以在视图部分使用{if $product.quantity < 0}{/if}
但我的目标是在控制器中执行它。这里是我的代码:
function hookHome($params)
{
global $smarty, $cookie;
$nb = intval(Configuration::get('HOME_NEW_PRODUCTS_NBR'));
$rand = intval(Configuration::get('HOME_NEW_PRODUCTS_RANDOM'));
if ($rand == 1) {
$products = Product::getNewProducts(intval($cookie->id_lang), 0, $nb);
if ($products)
{
shuffle($products);
array_slice($products, ($nb ? $nb : 10));
}
}
else
{
$products = Product::getNewProducts(intval($cookie->id_lang), NULL - 0, (intval($nb ? $nb : 4)), false, NULL, NULL);
}
$smarty->assign(array(
....
'products' => $products,
....
);
return $this->display(__FILE__, 'homenewproducts.tpl');
}
我怎么能覆盖类Product
因此,该方法getNewProducts
考虑排除产品脱销?
或者至少,我如何从$products
中删除数量= 0的产品使用PHP?
您的帮助表示赞赏。
答
好了,我现在使用的解决方案是:
在product.php
,我改变了SQL查询中getNewProducts
方法中的NewProductsController
,使其考虑到如果产品在股票
我添加可用第2086行的AND 'quantity'!=0
和第2086行的$sql->where('p.'quantity' != 0');
。 Prestashop 1.6.0.6。
当然,最好覆盖类Product.php而不是修改它。
我希望它能提供帮助。