sdc Posted August 7, 2016 Share Posted August 7, 2016 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 More sharing options...
rocky Posted August 8, 2016 Share Posted August 8, 2016 Which hook or function are you executing that code? Link to comment Share on other sites More sharing options...
Tung at RockPOS.com Posted August 8, 2016 Share Posted August 8, 2016 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 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