prestashop - 如何在 Prestashop 1.6 中创建对象购物车
问题描述
我在 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 效果很好。谢谢你的帮助。
亲切的问候
解决方案
您需要定义货币的 id。
使用该代码,您可以在购物车中分配上下文中定义的货币:
$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'
));
}
推荐阅读
- python - Python线性回归组合问题
- php - WooCommerce 的 Mailchimp:删除同步问题的订阅者标签
- amazon-s3 - AWS Glue 和 S3 访问点
- node.js - 如何在 CodeIgniter 4 中集成节点包?
- bash - Bash脚本完成后没有退出,为什么?
- angularjs - 健全性检查:是否可以在 HLS(m3u8)视频流和 angularjs 应用程序(ui)之间进行代理?
- python - 用列表理解解决方案替换 numpy isin
- flutter - Flutter 设置状态未使用新数据更新我的 UI
- python - 瑞典语字符解码错误:这是 API 的错还是我的错?
- python - 无法创建 urls.yaml 以使用 urlwatch