繁体   English   中英

如何在Prestashop 1.6.7中的购物车中添加产品

[英]How to add Product in Cart in Prestashop 1.6.7

我试图在Prestashop 1.6.7的购物车中添加产品。

但这不起作用。

下面是我的代码:

$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);

但是上面的代码不起作用。

我以某种方式管理我的代码如下:

global $context;

$context=Context::getContext();//new Cart();

$id_cart=$context->cookie->__get('id_cart');
$lan_id = $context->cookie->__get('id_lang');
$cur_id = $context->cookie->__get('id_currency');   


$products_ids=16571;
$cart=new Cart($id_cart);
$cart->id_currency=$cur_id;
$cart->id_lang=$lan_id;
$this->context->cart->update();
$cart->updateQty(1,16571);

但是承运人有一个错误

没有提供此地址的承运人。

尝试在代码末尾添加以下代码。

        $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);

我在其中添加了一些静态运营商ID

classes/Cart.php

getPackageList函数中的行号。 大约 1892年

if (empty($product['carrier_list'])) {
    $product['carrier_list'] = array(
                                '0' => 10,
                                '1' => 11
                               );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM