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

时间:2018-09-14 06:15:51

标签: php prestashop

我想创建一个特定的模块来添加定制产品。这样,我开发了下一个源代码(正在运行):

/* 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]'])并添加更多信息(字符串/ varchar)?

1 个答案:

答案 0 :(得分:0)

要更改价格,您可以使用:

$product->price = your price here;
$product->update();