【问题标题】:count items in cart different on_sale计算购物车中不同的商品 on_sale
【发布时间】:2017-04-25 00:29:49
【问题描述】:

我正在使用 prestashop 1.6,我在 classes/Cart.php 中创建了一个函数,这个计数购物车中的项目,但该项目是没有折扣或降价的产品。

/* @return int Cart Item not on_sale
*/
public function getTotalItems()
{
    $total_items = 0;

    $total_items = (int)Db::getInstance()->getValue('
        SELECT SUM(`quantity`)
        FROM `'._DB_PREFIX_.'cart_product`
        WHERE `id_cart` = '.(int)$id
        'AND p.`active` <> 1 AND p.on_sale <> 1'
    );

    return $total_items;
}

这是 shopping-cart.tpl 调用

{$cart->getTotalItems()|escape:'htmlall':'UTF-8'|number_format:0}

但是退货是 0,当然我的购物篮里有打折和不打折的产品。

怎么了?

【问题讨论】:

  • 首先,_DB_PREFIX_应该在开头和结尾都有下划线吗?如果是这样,那就太好了。其次,WHERE 子句的第一行最后需要另一个 .

标签: php sql shopping-cart cart prestashop-1.6


【解决方案1】:

(int)$id 将始终导致 0,因为它是未定义的。您需要使用$this-&gt;id 来获取购物车ID。

$total_items = (int)Db::getInstance()->getValue('
    SELECT SUM(`quantity`)
    FROM `'._DB_PREFIX_.'cart_product`
    WHERE `id_cart` = '.(int)$this->id.
    ' AND p.`active` <> 1 AND p.on_sale <> 1'
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 2023-01-12
    • 2019-02-02
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多