Jump to content

How do I use a certain hook to insert my function?


Recommended Posts

You would create a module, and in that module you would register the actionValidateOrder hook, which is executed whenever a new order is created.  You can then implement your logic in your module.

 

Thank You for your advice. Now I have these questions regarding the implementation:

 

1) I know that actionValidateOrder hook has these parametres:

    'cart' => (object) Cart object,
    'order' => (object) Order object,
    'customer' => (object) Customer object,
    'currency' => (object) Currency object,
    'orderStatus' => (object) OrderState object

 

I know how to access these values - for example for 'cart' it is: $id = $params['cart']->id.

 

Problem is that now I want to use customer´s details like his address or his firm. Tell me please how do I access these?

 

2) Can You tell me please if it is possible for one hook to use a variable of another hook? For example lets say I have 2 hooks: actionValidateOrder with a variable $id = $params['cart']->id inside it and I also have displayShoppingCart hook. Question is: Can I use $id variable from actionValidateOrder inside displayShoppingCart hook and how can I do that?

 

Thank You 

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

The company/firm for the customer is stored in the customer object

$company->customer

 

The company/firm for the address (because the address can be for the customer, or for the recipient of the order, or for the billing address which may not be the customers)

$address->company

 

A customer can have many different addresses, but an order can only have 2.  So from the order, you can obtain the ID of the addresses

$order->id_address_delivery

$order->id_address_invoice

 

Then you can create an address object, and access the address details

$address_delivery = new Address($order->id_address_delivery);

$address_invoice= new Address($order->id_address_invoice);

 

 

As for sharing variables, no I don't think what you are showing is possible.  Since those hooks would never happen at the same time.  You would have to store your variable value somewhere (cookie, database, file etc...) and manage it across different requests/sessions.  However in your example, there is no reason to share the Cart ID across sessions/requests.  You can access the Cart Id anytime using the context

$this->context->cart->id

 

Now that assumes you are dealing with the front office and a cart exists.  There would likely not be a cart object if the visitor is trying to contact you on the contact us page.

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