Pierrox15 Posted November 19, 2019 Share Posted November 19, 2019 Hello, I m creating a module to manage category on the front office and I've got a problem to clear cache when the product association change. When I join a product to a *non default* category the HookCategoryUpdate seem not be call. Perhaps i don't understanding how to use it? Below the code i use to clear my specific cache: I Don't know how I can get the new *non defaut* category association to clear it front office page cache public function hookActionProductUpdate($params){ $id_product = $params['id_product']; if ( $categories = Product::getProductCategories(intval($id_product))){ foreach ($categories as $id_category){ $this->clearCategoriesCache(intval($id_category)); } } } public function hookActionCategoryUpdate($params){ if($id_category = $params['id_category']){ $this->clearCategoriesCache(intval($id_category)); } } public function hookActionProductAdd($params){ $id_product = $params['id_product']; if ( $categories = Product::getProductCategories(intval($id_product))){ foreach ($categories as $id_category){ $this->clearCategoriesCache(intval($id_category)); } } } public function clearCategoriesCache($id_category){ return $this->_clearCache('productscategory.tpl','productscategory|'. $id_category); } Thx for your help Link to comment Share on other sites More sharing options...
0 datakick Posted November 19, 2019 Share Posted November 19, 2019 hookActionXXXUpdate is called when object model properties are changed. So, when you save Product from your back office then hookActionProductUpdate is called. Unfortunately, at this point, only product properties has been saved to database. Category associations weren't saved yet, because they are not property of an object. Controlelr will save them a littile bit little bit later. That means your Product::getProductCategories(intval($id_product)) is probably retrieving old set of categories Link to comment Share on other sites More sharing options...
0 Pierrox15 Posted November 20, 2019 Author Share Posted November 20, 2019 (edited) Ok thx, So I get the POST values with `(array)Tools::getValue('categoryBox');` and seem to work. So actionCategoryUpdate is never call when a product changing Category? Edited November 20, 2019 by Pierrox15 Link to comment Share on other sites More sharing options...
Question
Pierrox15
Hello,
I m creating a module to manage category on the front office and I've got a problem to clear cache when the product association change.
When I join a product to a *non default* category the HookCategoryUpdate seem not be call.
Perhaps i don't understanding how to use it?
Below the code i use to clear my specific cache:
I Don't know how I can get the new *non defaut* category association
to clear it front office page cache
Thx for your help
Link to comment
Share on other sites
2 answers to this question
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