Jump to content

Edit History

Florian644

Florian644

Hello, 

I made a module where the customer is able to customize a product. On the front page of the module, the product is displayed as an SVG element, the customer can customize this SVG element with Javascript, the SVG element code is change in real time at every actions from the customers.
When the customer add the product to shopping cart, this function is called in the module's front controller :

// Add the product in shopping cart
    public function addToShoppingCart(){

        if ($this->context->cookie->id_cart){
            $cart = $this->context->cart;
        }

        if ($cart->id == null){
            $cart = new Cart();
            $cart->id_customer = (int)($this->context->cookie->id_customer);
            $cart->id_address_delivery = (int)  (Address::getFirstCustomerAddressId($cart->id_customer));
            $cart->id_address_invoice = $cart->id_address_delivery;
            $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->add();
            $this->context->cookie->id_cart = (int)($cart->id);    
        }
        
        $cart->gift_message = Tools::getValue('svgTemplateResult');
        $cart->update();
	
        // Update the shopping cart
        $cart->updateQty(1, $this->getProductId(), $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);
    }

As you can see, I get the cart if it's already created or create it if not.

I add  Tools::getValue('svgTemplateResult')  which is the SVG element code as a string, to a place in the Cart object and try to get it back in my main php file of the module with the actionValidateOrder hook like this :

public function hookActionValidateOrder($params)
{
    echo "<pre>";
    print_r($params['cart']);
    echo "<pre>";
    
    die();
}

But the value is not in gift_message anymore and by having a look in the database, I found when it's deleted.

In the checkout page, just when i chose a Carrier, BOUM, the value is deleted from the Cart object and cannot be find once the actionValidateOrder is triggered.

Please, how can I do pass this value from the Cart object to the Order object. Is there an actionHook when the Carrier is chosen ? I found some but haven't tried yet. I will now.

Also, I made an override to add a field to OrderDetail object, the field just wait to be filled with this value and finally get the SVG element displayed in the order details summary in Back Office.

Florian644

Florian644

Hello, 

I made a module where the customer is able to customize a product. On the front page of the module, the product is displayed as an SVG element, the customer can customize this SVG element with Javascript, the SVG element code is change in real time at every actions from the customers.
When the customer add the product to shopping cart, this function is called in the module's front controller :

// Add the product in shopping cart
    public function addToShoppingCart(){

        if ($this->context->cookie->id_cart){
            $cart = $this->context->cart;
        }

        if ($cart->id == null){
            $cart = new Cart();
            $cart->id_customer = (int)($this->context->cookie->id_customer);
            $cart->id_address_delivery = (int)  (Address::getFirstCustomerAddressId($cart->id_customer));
            $cart->id_address_invoice = $cart->id_address_delivery;
            $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->add();
            $this->context->cookie->id_cart = (int)($cart->id);    
        }
        
        $cart->gift_message = Tools::getValue('svgTemplateResult');
        $cart->update();
	
        // Update the shopping cart
        $cart->updateQty(1, $this->getProductId(), $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);
    }

As you can see, I get the cart if it's already created or create it if not.

I add  Tools::getValue('svgTemplateResult')  which is the SVG element code as a string, to a place in the Cart object and try to get it back in my main php file of the module with the actionValidateOrder hook like this :

public function hookActionValidateOrder($params)
{
    echo "<pre>";
    print_r($params['cart']);
    echo "<pre>";
    
    die();
}

But the value is not in gift_message anymore and by having a look in the database, I found when it's deleted.

In the checkout page, just when i chose a Carrier, BOUM, the value is deleted from the Cart object and cannot be find once the actionValidateOrder is triggered.

Please, how can I do pass this value from the Cart object to the Order object. Is there an actionHook when the Carrier is chosen ? I found some but I cannot reach to connect my module to it don't know why.

Also, I made an override to add a field to OrderDetail object, the field just wait to be filled with this value and finally get the SVG element displayed in the order details summary in Back Office.

×
×
  • Create New...