Jump to content

Customer Address Save Action Hook


Recommended Posts

Not directly from the account creation process as far as I'm aware but every time an object is saved or updated 4 hooks are called:

 

actionObjectAddBefore

actionObject<CLASSNAME>AddBefore

actionObjectAddAfter

actionObject<CLASSNAME>AddAfter

 

actionObjectUpdateBefore

actionObject<CLASSNAME>UpdateBefore

actionObjectUpdateAfter

actionObject<CLASSNAME>UpdateAfter

 

So in your case you should be able to hook into actionObjectAddressAddAfter.

 

hope this helps

Link to comment
Share on other sites

  • 8 months later...
  • 2 years later...

I just wanted to contribute to this even though the thread is old (and my own experience is with Prestashop 1.7).  The code I was working with is intended to act specifically after an address has been updated in the back-office, and I have yet to test it in the front-office (though eventual goal is to have it apply to address update actions in general).

The hook to attach turned out to be actionObjectCustomerAddressUpdateAfter.  So, logically, the hook to trigger before the update is actionObjectCustomerAddressUpdateBefore.

I was pulling my hair out because another hook I had prior set up - actionObjectAddressAddAfter - triggers fine, so I was attempting to attach to the hook actionObjectAddressUpdateAfter to no avail.

To others who might tread down the same path as me, I actually just plain hooked into the generic actionObjectUpdateAfter and had it log the contents of $params somewhere I could review them.  Examining the contents of $params passed from the generic post-object-update hook triggered when I undertook the specific action I was hooking into, I found the object in question was a CustomerAddress object and thus the proper hook name to target it specifically would be CustomerAddress related rather than simply Address.

Ultimately for my issue it looks like at some point the object type stopped being Address and became CustomerAddress.  Not sure why, not going to puzzle over it more as the behavior now works.

Link to comment
Share on other sites

  • 1 year later...

Hi Kbasotti,

I have to do the same thing in prestashop 1.7.6.
I want call an "actionObjectCustomerAddressUpdateAfter" after that address has been modified, so I have these question:

1) I registered the "actionObjectCustomerAddressUpdateAfter" in Install method  module: " $this->registerHook('actionObjectCustomerAddressUpdateAfter')  "

2) Where you call to the "actionObjectCustomerAddressUpdateAfter" in " public function processSave()" of override of "AdminAddressController"?

3) Have you customize de Address form in prestashop 1.7 without used "ovirrede", but used the hook like "actionCustomerFormBuilderModifier" and "actionCustomerGridDefinitionModifier" how we can do with the customer form?

tnx

Link to comment
Share on other sites

It's been over a year and my memory of this particular project is not terribly sharp, so with that warning:

1: Not sure if that's a question, if so I'm having trouble understanding it.

2: I believe you are asking when I manually triggered the customerAddressUpdateAfter action.  I did not manually trigger the action that I was hooking into - I was just adding additional logic to hook into existing inbuilt triggering of that action by registering hook "actionObjectCustomerAddressUpdateAfter" as well as implementing a function named hookActionObjectCustomerAddressUpdateAfter() with one parameter inventively named "$params".

3: Likewise, I didn't override or otherwise alter the address forms.  My plugin acted as a bridge between Prestashop and a custom ERP solution, so all that it really needed to do was to hook into CRUD operations of Prestashop entities and mirror those operations to the ERP system (or vice-versa, but that was actually a distinct extension of the ERP system that resided outside of Prestashop).

What you are doing sounds like you are extending address entities and the interfaces for managing them, which is a little deeper into Prestashop's extension/plugin functionality than I ever had to delve to get my solution running.  I will provide advice if I can but it sounds like I dipped my toe into a pool that you're going to be walking in knee-deep.

 

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

Hi,

for my first question I have registered the in the instal like that:

 public function install()
    {
        //hookActionCustomerGridDefinitionModifier
        return parent::install() &&
            $this->registerHook('actionSendToPanthera') &&
            $this->registerHook('actionObjectCustomerAddressUpdateAfter') &&

            $this->registerHook('actionAddressGridDefinitionModifier') &&
            $this->registerHook('actionCustomerGridDefinitionModifier') &&
            $this->registerHook('actionCustomerGridQueryBuilderModifier') &&
            $this->registerHook('actionCustomerFormBuilderModifier') &&
            $this->registerHook('actionAfterCreateCustomerFormHandler') &&
            $this->registerHook('actionAfterUpdateCustomerFormHandler') &&
            $this->registerHook('actionAdminCustomersControllerSaveAfter'); // &&
            //$this->installTables();

    }
 

and implement the test function


    public function hookActionObjectCustomerAddressUpdateAfter($parameters)
    {
        // This is where you can modify/alter the behavior of PrestaShop.
        // The content of $parameters will depend on what is sent when the hook is dispatched.
        $error = "hello world !!!";
    }

2) I have called the hook in address funnction  "PostProcess" at the end of the function, like that:

   public function processSave()
    {

 [

 

        Hook::exec('actionObjectCustomerAddressUpdateAfter');

        return $return;
    }

I'm doing the same think, I'm doing a connecto between ERP Panthera and Prestashop, so when some one change the data Prestashop should call an hook that has the deal to call the ERP e send it the record modifiedhook that has the deal to call ERP e send it the record modified.  The problem is that the doen't work.

3) I have to customize the grid and form and for the customer it was been easy using the hook:

) &&

            $this->registerHook('actionAddressGridDefinitionModifier') &&
            $this->registerHook('actionCustomerGridDefinitionModifier') &&
            $this->registerHook('actionCustomerGridQueryBuilderModifier') &&
            $this->registerHook('actionCustomerFormBuilderModifier') &&
            $this->registerHook('actionAfterCreateCustomerFormHandler') &&
            $this->registerHook('actionAfterUpdateCustomerFormHandler') &&
            $this->registerHook('actionAdminCustomersControllerSaveAfter'); // &&

but when I try to use my customize hook or the hook how you wrote "$this->registerHook('actionObjectCustomerAddressUpdateAfter') &&" nothing happened

can you pass me an example?

tnx

Link to comment
Share on other sites

Hey, FYI - you can use the code option (<>) to more easily format/display code snippets for others to read.

For example from your post:

Without code formatting:

public function hookActionObjectCustomerAddressUpdateAfter($parameters)
    {
        // This is where you can modify/alter the behavior of PrestaShop.
        // The content of $parameters will depend on what is sent when the hook is dispatched.
        $error = "hello world !!!";
    }

Versus with code formatting:

public function hookActionObjectCustomerAddressUpdateAfter($parameters)
    {
        // This is where you can modify/alter the behavior of PrestaShop.
        // The content of $parameters will depend on what is sent when the hook is dispatched.
        $error = "hello world !!!";
    }

Anyhow, digression aside...

One thing to note about these plugins, if you weren't aware, is that install() is called only once when you originally install the plugin.  Revisions to install() do not actually register new hooks (or unregister existing ones).  You can go into some interface in the administrative section to manually register/deregister hooks from a plugin, but I don't remember exactly where that is (and I recall it moving from version to version so even if I remembered, my advice on that might not apply to your copy).  I would just cheat and add calls to registerHook (and unregisterHook) to __construct(), reload the page/plugin once, then remove them.

I did this because I am lazy, and a horrible programmer, and a terrible person.  I am not advocating this easy way to register/deregister hooks on the fly without navigating Prestashop's arcane hook registration management interface or uninstalling/reinstalling your plugin after every major revision.

So, with your code... are you echoing $error at any point?  Or is $error some global that will be echoed or handled independently of any code written on your part?

Like, if you're testing whether or not your scripts are actually reaching into hookActionObjectCustomerAddressUpdateAfter() during execution by assigning "hello world !!!" to $error, I'm not seeing any actual output of $error (print, echo, var_dump, whatever) to pass that indication anywhere that you'd be able to read/acknowledge it.

Basically, with your code, I'd first do something to test whether or not processSave() is being reached/triggered.  If it is, then I'd do something to test whether or not hookActionObjectCustomerAddressUpdateAfter() is being triggered.  Have you done both of those, and if so what results have you seen?

If there's some handy function to let you dump a list of all hooks your particular plugin has registered, that might also help - but if such a function exists I do not know its name.

Link to comment
Share on other sites

solved, thanks.

my hook was registered in my module, I don't know why the istruction into the install didn't work. In my override "AdminAddressController" into "ProcessSave" method at the end, before the istruction "return" I have putted

        $error = Hook::registerHook($this,"actionAdminAddressesControllerSaveAfter");
        $resulttt = Hook::exec("actionAdminAddressesControllerSaveAfter",["panthera_id" => "10001"]);

into the class "Hook" you can find alla methods to find all hook/module registered

 

[SOLVED]

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