我正在尝试在Prestashop 1.6.7中的Cart中添加产品。
但它不起作用。
以下是我的代码:
$context=Context::getContext();//new Cart();
$id_cart=$context->cookie->__get('id_cart');
$lan_id = $this->context->language->id;
$cur_id = $this->context->currency->id;
$products_ids=16571;
$cart=new Cart($id_cart);
$cart->id_currency=$cur_id;
$cart->id_lang=$lan_id;
$cart->updateQty(1,$products_ids, null, false);
但上面的代码无效。
答案 0 :(得分:0)
我按照以下方式管理我的代码:
export class BaPageTop implements OnInit{
public userdata:UserData;
constructor(private _state:GlobalState,public userData:UserData) {}
ngOnInit(): void {
this.userdata=this.userData;
但 carrier
有一个错误没有可用的运营商提供此地址。
答案 1 :(得分:0)
尝试在代码末尾添加以下代码。
$this->context->cart->save();
$this->context->cookie->id_cart = (int)$this->context->cart->id;
$this->context->cookie->write();
$this->context->cart->autosetProductAddress();
Hook::exec('actionAuthentication');
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
答案 2 :(得分:0)
I add some static Carrier ID in
classes/Cart.php
in getPackageList function at line no. approx. 1892
if (empty($product['carrier_list'])) {
$product['carrier_list'] = array(
'0' => 10,
'1' => 11
);
}