我刚刚开始学习prestashop模块开发,我对一些事情很好奇。
我想创建一个类似于T恤设计师的模块,用户可以从模块中选择任何他们喜欢的T恤并进行自定义。是否有可能将产品传递到prestashop中不存在的购物车?我的意思是我需要定制产品只能在我的T恤模块中看到,我不想通过后端手动添加它们作为产品。我只是想将定制产品传递给购物车。是否有任何prestashop内置函数可以执行此操作?
答案 0 :(得分:0)
您可以使用以下代码将产品添加到购物车中:
$this->id_product = (int) Tools::getValue('id_product', null);
$this->id_product_attribute = (int) Tools::getValue('id_product_attribute', Tools::getValue('ipa'));
$this->customization_id = (int) Tools::getValue('id_customization');
$this->qty = abs(Tools::getValue('qty', 1));
$this->id_address_delivery = (int) Tools::getValue('id_address_delivery');
if (!$this->context->cart->id) {
if (Context::getContext()->cookie->id_guest) {
$guest = new Guest(Context::getContext()->cookie->id_guest);
$this->context->cart->mobile_theme = $guest->mobile_theme;
}
$this->context->cart->add(); //create cart if not available
if ($this->context->cart->id) {
$this->context->cookie->id_cart = (int) $this->context->cart->id;
}
}
$this->context->cart->updateQty( //to add product into cart
$this->qty,
$this->id_product,
$this->id_product_attribute,
$this->customization_id,
Tools::getValue('op', 'up'),
$this->id_address_delivery
);