And what is your problem?
public function addToShoppingCart() { if ($this->context->cart->id){ $id_cart = $this->context->cart->id; } if (!$id_cart){ // not exists, create $cart = new Cart(); $cart->id_customer = (int)($this->context->cookie->id_customer); $cart->id_lang = (int)($this->context->cookie->id_lang); $cart->id_currency = (int)($this->context->cookie->id_currency); $cart->id_carrier = 1; $cart->recyclable = 0; $cart->gift = 0; $cart->gift_message = Tools::getValue('svgTemplateResult'); $cart->add(); $this->context->cookie->__set('id_cart', $cart->id); $data = [ 'cart' => $cart, 'product' => $product, 'id_product_attribute' => $id_product_attribute, 'id_customization' => $id_customization, 'quantity' => '1', 'operator' => 'up', 'id_address_delivery' => (int)(Address::getFirstCustomerAddressId($cart->id_customer)), 'id_address_invoice' => (int)(Address::getFirstCustomerAddressId($cart->id_customer)), 'shop' => $this->context->shop->id, 'auto_add_cart_rule' => true, ]; Hook::exec('actionCartUpdateQuantityBefore', $data); } else { // exists, update $cart = new Cart ((int) $id_cart); $cart->gift_message = Tools::getValue('svgTemplateResult'); $cart->update(); } }