Jump to content

discount not updated on the product page


sdc

Recommended Posts

Hi all,

 

I am developing new module and at some point I trigger a discount from the module like this :

 

        $specificPrice = new SpecificPrice();

 

        // dummy config
        $specificPrice->id_product = $id_product;

        $specificPrice->id_shop = $id_shop;

        ...
        $specificPrice->reduction = 0.09;
        $specificPrice->reduction_type = 'percentage';
        $specificPrice->from = date('Y-m-d H:i:s');
        $specificPrice->to = date('Y-m-d H:59:59');
       
        $specificPrice->add();

 

the problem is that the discount is there (added to the DB) but the UI not updated (discount not displayed on the product price section). it is displayed only after refresh the product page some seconds later.

same thing when delete the discount.

 

it seems that the discount is triggered by the module after the product price is loaded to the UI.

 

* is there any solution to make Prestashop aware that the product price has been changed and it should update itself? (like for example "invalidate()" in other APIs)

 

* otherwise, when should I apply this discount because it seems that all prduct hooks are called too late after the product page is loaded?

 

in other words, I want to trigger the discount before prestashop load the product price when loading the product page. so which product hook is called before that?

 

any help will be appreciated.

Link to comment
Share on other sites

Hello,

 

1. If it will be shown right after refreshing, it's due to static cache. 

Please refer to class Product::getPriceStatic(), then a few other functions invoked after that. You will be noticed that, the price is cached in a static attribute. That's said, the price is unchanged until the new request (refresh) is sent. 

That's imply executing this after adding the specific price:

Product::flushPriceCache()

2. If it's only shown up after some second later.

Personally, I don't think this happens. If it happens, it should happen in hours or days, not seconds.

Because this might relate to PrestaShop cache:

We sometimes execute this piece of code to clear PrestaShop cache:

        Tools::clearSmartyCache();
        Media::clearCache();

But be carefully, as it could lead to performance issue, because cache is not cached actually :)

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...