如何在Prestashop 1.7中将自定义产品添加到购物车?

问题描述 投票:0回答:1

我想创建一个特定的模块来添加自定义产品。通过这种方式,我开发了下一个源代码(它正在工作):

/* Data */
$id_product = (int)Tools::getValue('id_product');
$id_customization = (int)Tools::getValue('id_customization'); // = 0
$price_product = (int)Tools::getValue('priceform'); // nouveau prix

/* Create the cart */
if(!$this->context->cart->id) {

    /* Detect the user logged */
    if($this->context->cookie->id_guest) {
        $guest = new Guest($this->context->cookie->id_guest);
        $this->context->cart->mobile_theme = $guest->mobile_theme;
    }
    $this->context->cart->add();

    /* Create the cookie */
    if($this->context->cart->id) {
        $this->context->cookie->id_cart = (int)$this->context->cart->id;
    }
}

/* Select the cart */
$cart = $this->context->cart;

/* Select the product */
$product = new Product($id_product, true, (int)($this->context->cookie->id_lang));
$id_product_attribute = Product::getDefaultAttribute($id_product);

/* Add to cart */
$cart->updateQty(1, $id_product, $id_product_attribute, $id_customization);

但我不知道,如何改变价格,添加赤字($ _POST ['group [X]'])并添加更多信息(string / varchar)?

php prestashop
1个回答
0
投票

更改您可以使用的价格:

$product->price = your price here;
$product->update();
© www.soinside.com 2019 - 2024. All rights reserved.