cyberdoc Posted July 3, 2014 Share Posted July 3, 2014 Hi, i need to change the price of a product at runtime according to a complex calculation..now i update it successfully in the Ps_product table. but after the addition to cart it still shows 0(old price). Any idea why? is there another place i need to update this?? PS : ive checked in the db the changes are occuring Link to comment Share on other sites More sharing options...
PascalVG Posted July 3, 2014 Share Posted July 3, 2014 Maybe you need to re-load the object, to 'synchronize' with the database values? It all depends on when/where/how you make the changes... Please elaborate. Link to comment Share on other sites More sharing options...
cyberdoc Posted July 4, 2014 Author Share Posted July 4, 2014 basically i change the product price as per the other items in the cart.. so ive added a hook at displayshopping cart and get the products list from there, calculate the price as per that then update the price of my product via sql query. finally i add this product to cart using updateqty.. below is the code.. $cookie = $this->context->cookie; $sub_total=0; $products = $params['cart']->getProducts(true); // print_r($products); // print_r($cookie); foreach ($products as $product) { $result = Db::getInstance()->getRow('SELECT textarea FROM `'._DB_PREFIX_.'belvg_samplemodule` sample WHERE sample.`id_product` = '.$product['id_product']); // print_r($product['id_product']); $sub_total = $sub_total + $result['textarea']; } $result =DB::getInstance()->Execute('UPDATE `'. _DB_PREFIX_ .'product` SET `price` = ' .$sub_total. ' WHERE `id_product` = 9'); $params['cart']->updateQty(1, 9); $params['cart']->update(); 9 is the product id of my product.. Link to comment Share on other sites More sharing options...
cyberdoc Posted July 4, 2014 Author Share Posted July 4, 2014 any help guys? i've checked that when the previous value in the db is 10 and the code updates it to 15, then also in the cart its shown as 0.... Link to comment Share on other sites More sharing options...
cyberdoc Posted July 4, 2014 Author Share Posted July 4, 2014 Ok for anyone curious, i solved it. basically to update in the cart you need to update values both in the Ps_prduct and ps_product_shop table... Silly mistake but yeah someone may also miss it like i did! Link to comment Share on other sites More sharing options...
PascalVG Posted July 5, 2014 Share Posted July 5, 2014 Hi Cyberdoc, thanks for the update. Good you solved it and shared the solution.This may help others! I'll mark the topic as solved. Happy selling, pascal 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