Skip to content
Advertisement

PrestaShop: How to refresh cart after creating specifc price

I have small problem 😉 I working with PrestaShop 1.7.6.9 (manual instaltion on shared hosting) and 1.7.7.1 (docker image from PrestaShop) I create module where price is calculated via code and saved in DB via SpecificPrice class. Saving work excellent, but I have other problem. When i go to cart product priced didn’t change. But when I wait some time and refresh the cart page, product price is changed for specific price.

My Specific Price code

$specific_price = new SpecificPrice();
$specific_price->id_product = 10;
$specific_price->id_product_attribute = 43; 
$specific_price->id_cart = 3;
$specific_price->from_quantity = 10;
$specific_price->price = 78.000000;
$specific_price->reduction_type = 'amount';
$specific_price->reduction_tax = 1;
$specific_price->reduction = 0;
$specific_price->from = date("Y-m-d H:i:s");
$specific_price->to = date("Y-m-d H:i:s", strtotime('+1 year'));
$specific_price->id_shop = 1;
$specific_price->id_currency  = 1;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = 0;
$specific_price->add();

I found same problems in topics on prestashop forum, but without the answer

I try with:

Cache::clear();
$specific_price->flushCache();
Tools::generateIndex();
DB::getInstance()->execute('RESET QUERY CACHE;');
DB::getInstance()->execute('FLUSH QUERY CACHE;');
$cart->resetStaticCache();
$cart->update();

And i try update Cart via update method.

Has anyone had a similar problem?

Advertisement

Answer

After talk on pm with @KrystianPodemski, where he suggest change date from in specific price for 0000-00-00 00:00:00 and… it works 🙂 Now code for new specific price is:

$specific_price = new SpecificPrice();
$specific_price->id_product = 10;
$specific_price->id_product_attribute = 43; 
$specific_price->id_cart = 3;
$specific_price->from_quantity = 10;
$specific_price->price = 78.000000;
$specific_price->reduction_type = 'amount';
$specific_price->reduction_tax = 1;
$specific_price->reduction = 0;
$specific_price->from = date("0000-00-00 00:00:00");
$specific_price->to = date("Y-m-d H:i:s", strtotime('+1 year'));
$specific_price->id_shop = 1;
$specific_price->id_currency  = 1;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = 0;
$specific_price->add();
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement