3

First, thanks in advance for any insight.

I'm using the following in a simple extension to set the status for new orders with the aim that I can send an email template based on the customer's member group:

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

  if (ee()->session->userdata('group_id') == 10)
  {
    $status->name = "Commercial";
  }
  else
  {
    $status->name = "General";
  }

  $order->updateStatus($status);

  return $order;
}

When processing an order, the system correctly sets the status to either Commercial or General. However, no email is sent. If I switch to another status and then back to the desired status, the email does send. In other words, it seems that the emails are only triggered when manually selecting the status.

Note that I have default order status of "Received" that does not trigger any email templates. I've done this because I've found that if no default status is set no email templates ever get sent -- even when manually selected.

Also, when looking at the bottom of the order detail, I do see that both order statuses are logged: Received and Commercial (or General).

Any thoughts?

  • On a second look at the orders' status logs, it appears that the status change (via hook) occurs before the default status is set. – Chris Feb 26 '14 at 0:09
4

It mainly goes down to processing order. When the order is successfully placed Store then does a little housekeeping to round off the order completion process. It will look to set a default status before checking for any extensions latching on to the store_order_complete_end hook. So walking through the process with your specific extension code:

Order is completed:

1) Set the status of the order to the default set via the CP [Received]
2) Look for any emails associated with this status & send [none found so none sent]
3) Check for extensions using the store_order_complete_end hook [found your extension]
4) Check session data and set status name to "Commercial" or "General"
5) Update status and send any associated emails

So that is why a default email isn't getting sent. With regards to the status change then not automatically triggering any emails, are you sure you have email templates saved and linked to that status? Check in the database that the status are listed in exp_store_statuses:

enter image description here

and associated with corresponding email_ids in exp_store_emails:

enter image description here

Alternatively you could always look to try the store_order_complete_start hook which will be triggered before the default status is set (if there is one). You shouldn't then need to set a default status if you don't want to.

3

It looks like there is a problem with the logic in your extension. You don't want to change the name of a particular status when the order is complete - you want to change the status of the order. I would expect it to look something more like this:

public function store_order_complete_end($order)
{
    if (ee()->session->userdata('group_id') == 10)  
    {
        $status = Store\Model\Status::where('name', 'Commercial')->first();
    }
    else
    {
        $status = Store\Model\Status::where('name', 'General')->first();
    }        

    $order->updateStatus($status);    
}
  • How would you tag on a message to this status change? The message seems to not be a part of the status model – Aaron Apr 2 '15 at 15:57

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.