Jump to content

Hook objectCustomerUpdateAfter not available


Recommended Posts

Hi there,

I'm kind of new to Prestashop module development, but I have some solid background with PHP and also with symphony.

I'm currently facing a strange issue that I just can't explain to myself. Here's the thing:  I need to link my module to the hook for customer creation and update, and as I need to catch that in both FO and BO, I'm using the objectCustomerAddAfter and objectCustomerUpdateAfter. However, I can not transplant it in the BO because it's not in the dropdown list of available hooks. In this list I correctly see the other hooks I'm using in my module (objectCustomerAddAfter, OrderEdited, OrderStatusUpdate, addWebserviceResources) but not this one! Weirder thing : if I just change 

$this->registerHook('objectCustomerUpdateAfter')

...

public function hookActionObjectCustomerUpdateAfter($params){...}

to 

$this->registerHook('objectCustomerUpdateBefore')

...

public function hookActionObjectCustomerUpdateBefore($params){...}

in my module main php file, I see it appears in the transplant list, but never happens with objectCustomerUpdateAfter 😅

Do you have some idea?

Thanks !

Link to comment
Share on other sites

public function install()
{
    if (Shop::isFeatureActive()) {
        Shop::setContext(Shop::CONTEXT_ALL);
    }

   return (
        parent::install() 
        && $this->registerHook('actionObjectCustomerUpdateAfter')
    ); 
}

public function uninstall()
{
    return (
        parent::uninstall() 
        && $this->unregisterHook('actionObjectCustomerUpdateAfter')
    );
}

public function hookActionObjectCustomerUpdateAfter($params)
{
	$idCustomer = (int)$params['object']->id;
	$customer = new Customer((int)$idCustomer);
	$customerFirstname = $customer->firstname;
	$customerLastname = $customer->lastname;

	/* deactive customer, add siret, add ape */
	$db = Db::getInstance();
	$db->update('customer', 
		array(
			'active' => 0,
			'ape' => pSQL('12345678'),
			'siret' => pSQL('XA123456')
		), 
		'id_customer = '.(int)$idCustomer
	);
}

 

Edited by knacky (see edit history)
Link to comment
Share on other sites

Thanks for the example, but didn't really help as this is almost exactly what I have in my code.

Finnally I figured it out by uninstalling completely the module, unregistering hooks manually and installing it again and the CustomerUpdateAfter eventually showed up.

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