3

I'm just starting to work with Store 2.x and wondering if it's possible for me to create an extension that updates the order status once the order is complete. I know I'm needing to use the 'store_order_complete_end' hook, but not sure how I can update the status at this point. Can somebody point me in the right direction? I'm basically wanting to update the status to one of 2 things depending on what products they are buying.

Thanks, Dan

4

Derek was very close. I actually wrote a similar answer to this the other day.

You need to find the actual status before you update the order. Since you already have the $order object, all you need to do is this:

$status = Store\Model\Status::where('name', $status_name)->first();
$order->updateStatus($status);

FYI in case you are wondering, you can loop through the order items like this:

foreach ($order->items as $item) {
    echo($item->entry_id); // etc
}
| improve this answer | |
  • Great - I'm sure that will work fine - I'll check next week and let you know if I have any problems, but I can't see why I would. Thank you! – Dan Kingsley Jan 25 '14 at 14:13
  • It's cool that you can still call the built in functions from store. Really makes the site so much more dynamic! – heinkasner Jul 4 '14 at 12:19
3

If you do a print_r($order) inside of your extension, you'll see what you have access to inside of the $order object/array.

You can then loop through the order items it contains and check for your products, then update the exp_store_orders table with a new status for that order (I'm sure its _order_id is contained in the $order object as well).

| improve this answer | |
  • Thanks - I was really wondering if there was a way to call the already updateStatus that already exists and give it a new status. Ideally I want it to send the email and update the status history as well, not just updating the actual status. Sorry for not being clear on that one! – Dan Kingsley Jan 24 '14 at 14:32
  • Shot in the dark here, but try this in your extension: ee()->store->order->updateStatus('status_name');. – Derek Hogue Jan 24 '14 at 15:01
  • Unfortunately not... I get the following error: Fatal error: Class 'Store\Service\OrderService' not found in *********/expressionengine/third_party/store/src/Store/Container.php on line 32 – Dan Kingsley Jan 24 '14 at 15:18
  • I'll ping Adrian on this. – Derek Hogue Jan 24 '14 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.