我在Prestashop 1.6中创建购物车对象时遇到问题。我有一个错误:
2019/11/02 - 22:02:40: Property Cart->id_currency is empty at line 917 in file classes/ObjectModel.php
在调试模式下,我没有看到购物车对象的ID,这是我认为的问题。这是我的代码:
if($id_product && $checkQty >= $quantity)
{
if (!$this->context->cart->id)
{
$this->context->cart->add();
$cart = new Cart();
if ($this->context->cart->id)
$this->context->cookie->id_cart = (int)$this->context->cart->id;
}else
{
$cart = new Cart($this->context->cookie->id_cart);
}
$cart->updateQty(
$quantity,
$id_product,
$id_product_attribute = null,
$id_customization = false,
$operator = 'up',
$id_address_delivery = 0,
$shop = null,
$auto_add_cart_rule = true
);
$this->context->smarty->assign(array(
'confirmation' => '1'
));
}
当然,当我有$ cart-> id时,updateQty效果很好。感谢您的帮助。
亲切的问候
使用该代码,您在购物车中根据上下文中定义的货币分配了货币:
$cart->id_currency = $context->cookie->id_currency;
因此,在您的代码中,它必须看起来像这样:
if($id_product && $checkQty >= $quantity) { if (!$this->context->cart->id) { $this->context->cart->add(); $cart = new Cart(); if ($this->context->cart->id) $this->context->cookie->id_cart = (int)$this->context->cart->id; }else { $cart = new Cart($this->context->cookie->id_cart); } $cart->id_currency = $this->context->cookie->id_currency; $cart->updateQty( $quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true ); $this->context->smarty->assign(array( 'confirmation' => '1' )); }