0

When I send out my transactional email programatically, I'm not getting any items in a table like I do when the email is sent automatically.

Looking into the templates, the information is pulled across via:

{{layout handle="sales_email_order_items" order=$order}}

This is sending directive:

$emailTemplate = Mage::getModel('core/email_template')->loadByCode("More Information Required");
$emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/email', Mage::app()->getStore()->getStoreId()));
$emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/name', Mage::app()->getStore()->getStoreId()));
$emailTemplate->send($order->getCustomerEmail(), $order->getCustomerName(), [
    'order' => $order,
    'customer' => $order->getCustomerName(),
    'dateAndTime' => $order->getCreatedAt()
]);

All the data is filled correctly, except the order items grid. Nothing is displayed for this.

Update
To answer the question in the comments, the $order variable is generated as a result of an observer action on an event (in this case, sales_order_save_after). The variable that eventually becomes $order (when passed into a function) is formed as follows:

$observer->getEvent()->getData('data_object')

This contains a standard order object, of the following class: Mage_Sales_Model_Order

8
  • What do you get if you dump your $order var?
    – mbalparda
    Nov 10, 2014 at 14:49
  • @mbalparda I've updated the question with your query in mind.
    – Dan Hanly
    Nov 10, 2014 at 15:04
  • Do you have "{{var items_html}}" after "{{layout handle="sales_email_order_items" order=$order}}"? Look here: magento.stackexchange.com/questions/7484/…
    – Kalpesh
    Nov 10, 2014 at 21:06
  • I'm afraid that adding {{var items_html}} doesn't seem to help either.
    – Dan Hanly
    Nov 11, 2014 at 7:52
  • In your call to $emailTemplate->send, is that pseudo-code? See your third argument. You can't construct an array in PHP with brackets like that ([]) - it would throw an exception. Dec 3, 2014 at 16:32

1 Answer 1

1
+200

I'll take a shot in the dark.
If you send e-mails from an "area agnostic" script then the layout directive does not know from where to load the handle sales_email_order_items.
Take a look at the layoutDirective method from the Mage_Core_Model_Email_Template_Filter class. This is the class that parses and interprets the email templates:

    if (isset($params['area'])) {
        $layout->setArea($params['area']);
    }
    else {
        $layout->setArea(Mage::app()->getLayout()->getArea());
    }

In your case $params['area'] is not set and you fall on the else case.
but here Mage::app()->getLayout()->getArea() most probably has no value.

You can try to change this

{{layout handle="sales_email_order_items" order=$order}}

to this

{{layout handle="sales_email_order_items" order=$order area="frontend"}}

or

{{layout handle="sales_email_order_items" order=$order area="adminhtml"}}

to see what happens.

6
  • I'm afraid neither frontend or adminhtml will work in my case. Thanks for your help though!
    – Dan Hanly
    Dec 4, 2014 at 13:53
  • 1
    @DanHanly. Sorry. Apparently I'm not that good at shooting in the dark. At least you have a place to start debugging. layoutDirective is the start point.
    – Marius
    Dec 4, 2014 at 13:55
  • 1
    The 'area' point was a good one, though it wasn't appropriate to add the it into the layout handle declaration. Before I begin adding parameters to the order, I needed to add the following line - $emailTemplate->setDesignConfig(['area' => 'frontend', 'store' => $storeId]); This meant that the email itself was configured to utilise a specific area. Your thought process led me to discover this answer, so thanks very much for that.
    – Dan Hanly
    Dec 5, 2014 at 14:05
  • @DanHanly. AHA. I knew it was something about the area. Nice call on the the setDesignConfig. I learned something from this question also :).
    – Marius
    Dec 5, 2014 at 14:15
  • 1
    @DanHanly. Thanks. But I feel a little bad that I didn't give a right answer. I feel like I don't really deserve the full bounty. :)
    – Marius
    Dec 10, 2014 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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