Php Prestashop 1.5如何从模块向购物车添加产品

Php Prestashop 1.5如何从模块向购物车添加产品,php,prestashop,Php,Prestashop,我刚开始学习prestashop模块开发,我对一些事情很好奇 我想创建一个类似于t恤设计师的模块,用户可以从该模块中选择他们喜欢的任何t恤并进行定制。是否有可能将不存在于prestashop中的产品传递给购物车?我的意思是,我需要定制的产品只在我的t恤模块中可见,我不想通过后端手动添加它们作为产品。我只是想把定制的产品传给购物车。是否有任何prestashop内置功能可以执行此操作?您可以使用以下代码将产品添加到购物车中: $this->id_product = (int)

我刚开始学习prestashop模块开发,我对一些事情很好奇


我想创建一个类似于t恤设计师的模块,用户可以从该模块中选择他们喜欢的任何t恤并进行定制。是否有可能将不存在于prestashop中的产品传递给购物车?我的意思是,我需要定制的产品只在我的t恤模块中可见,我不想通过后端手动添加它们作为产品。我只是想把定制的产品传给购物车。是否有任何prestashop内置功能可以执行此操作?

您可以使用以下代码将产品添加到购物车中:

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