从新产品列表中排除缺货产品 - Prestashop

时间:2014-07-11 15:22:13

标签: prestashop prestashop-1.6

我正在使用一个在主页中显示新添加产品的模块。我需要自定义模块,以便此列表不包含已售出的产品。换句话说,如果产品在被禁止的天数之前缺货,则新产品已经结束,则不要在列表中显示该产品。

我可以使用{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考虑将产品缺货排除在外?

或者至少,如何使用PHP从$products数量= 0的产品中删除?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

嗯,我现在使用的解决方案是:

product.php中,我在getNewProducts内的NewProductsController方法中更改了sql查询,以便考虑产品是否有库存

我在第2062行添加了AND 'quantity'!=0,在第2086行添加了$sql->where('p.'quantity' != 0');。 Prestashop 1.6.0.6。

当然,最好覆盖classe Product.php而不是修改它。

我希望它可以提供帮助。

相关问题