繁体   English   中英

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

[英]How to add a custom product to cart in Prestashop 1.7?

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

/* 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)?

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

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

暂无
暂无

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

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