onAfterOrderUpdate not show Cart object

  • Posts: 147
  • Thank you received: 7
7 months 2 weeks ago #343811

-- HikaShop version -- : 4.4.5

i have two different site with hikashop and i write some code in history plugin . in one of that it is work and in other it is not work.
when i dump for show all inside $order the first(hika 4.4.2) return Cart and the second(hika4.4.5) not return Cart. look at picture.


Please Log in or Create an account to join the conversation.

  • Posts: 78298
  • Thank you received: 12367
7 months 2 weeks ago #343815


Like all the "update" events, the onAfterOrderUpdate's first parameter contains the data being saved in the database.
This depends on what the code calling the class.order's save method provided.
To update an order the minimum required is to provide the order_id. For example:

$order = new stdClass();
$order->order_id = xxx;
$orderClass = hikashop_get('class.order');
This will provide to the onAfterOrderUpdate event with an object with 4 things:
- the old attribute which contains an object of the order data in the database before the data in the database was updated
- the history attribute, which contains a history object with generic information going into the "history" table for that order
- the order_id that the code set in $order to target the corresponding order
- the order_modified which contains the current unix timestamp to be saved in the database
That's the only things you'll always have in that first parameter of onAfterOrderUpdate. Anything else is added or not by the code calling the save function and as a plugin implementing the event you have no guarantee that they will be provided.

The "cart" attribute might be available when an order is updated in the same thread as it's being created, or it might be set by the email system when the email tags are being generated. You can rely on that attribute being always present in the first parameter of the event. If it's added by the emails and you disable the emails in System>Emails, then the cart attribute wouldn't be provided for example. And if you run a mass action to update orders, the emails won't be sent and that attribute won't be there either.

Note however that the cart attribute is just the data returned by loadFullOrder
So you could just have that code at the beginning of your code:
if(empty($order->cart)) {
 $orderClass = hikashop_get('class.order');
$order->cart = $orderClass->loadFullOrder($order->order_id, false, false);

The following user(s) said Thank You: sadaf3d

Please Log in or Create an account to join the conversation.

Time to create page: 0.067 seconds
Powered by Kunena Forum