Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
Pierrox15

HookCategoryUpdate seem not be call when changing product to non defaut category

Question

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

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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 

Share this post


Link to post
Share on other sites
  • 0

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 by Pierrox15

Share this post


Link to post
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...