Jump to content

Recommended Posts

Hello everyone,

 

I have made a module to create a customized product.

 

By pressing the "add to cart" button a specific price is inserted into the "specific_price" table of the database. This price is also connected with the current cart-id which I get with this code:

 

{$context = Context::getContext()}
{if is_null($context->cart->id)}
{$context->cart->add()}
{/if}
{$ggg = $context->cart->id}
 
(The code is written in the tpl-file of the module)
 
My problem is, that the first time you visit my page and customize your product and add it to the cart, you will get the product with the standard price. After reloading the page or adding a new customized product everything works fine.
 
I think that there is just a little error in my code or something isn't updating correctly.
 
Thanks for your help!!
Link to comment
Share on other sites

I had the same problem 
 
I added this code if the User enter to page product for example in (hookdisplayProductButtons) create new cart if needed and works fine.
 
// get cart id if exists
if ($this->context->cookie->id_cart)
{
    $cart = new Cart($this->context->cookie->id_cart);
}

// create new cart if needed
if (!isset($cart) OR !$cart->id)
{
    $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->update();
}

Hope it helps!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...