kaktus.m Posted April 14, 2017 Share Posted April 14, 2017 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 More sharing options...
abdess Posted April 16, 2017 Share Posted April 16, 2017 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 More sharing options...
kaktus.m Posted April 19, 2017 Author Share Posted April 19, 2017 Hello, where exactly did you put your code? Link to comment Share on other sites More sharing options...
abdess Posted April 19, 2017 Share Posted April 19, 2017 this code create new cart if cart not exist Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now