2

Trying to set different text for registered and guest customers order confirmation email (using single template, not sure why Magento has two different settings for this?) I've come across that {{if order.getCustomerIsGuest()}} always evaluates to true rendering {{else}} useless

I worked it around by using {{if order.getCustomerGroupId()}} but hoping someone can shed some light what can be culprit of this and to avoid other's pitfalls trying to implement this logic the same way as I originally did

5
  • Just wondering what the point of that is - why not just make two templates and apply one to be sent to guests in the admin config?
    – McNab
    Oct 19 '13 at 11:16
  • @McNab thing is templates are exactly the same, with just one difference about tracking order info hence guest customers don't have accounts
    – Zifius
    Oct 19 '13 at 11:31
  • 1
    Fair enough, I know what you mean - seems like unneccessary duplication. The only reason I mention it is because the Magento default Order confirmation and Guest Order confirmations themselves are also virtually identical....and if further changes are required later on it starts making less and less sense to have them running through the same template with conditional statements.
    – McNab
    Oct 19 '13 at 11:34
  • 1
    @McNab agreed, if that will be the case I'll probably separate them back, but main question here why obvious getCustomerIsGuest() which can be only 1 or 0 always evaluates to true
    – Zifius
    Oct 19 '13 at 11:38
  • How did you solve the issue? Post an answer here, please. Dec 28 '13 at 14:14
1

I understand why your code doesn't work. See Varien_Filter_Template::ifDirective(): It compares '0' or '1' to '', which will both return false.

What I don't understand is why the same construct with customer_group_id does work. The only thing I can think of is that customer_group_id is filled with NULL in sales_flat_order table (which it isn't in my installation).

The only 2 simple solutions (implementation in < 1h) I can think of:

  • Extend Mage_Sales_Model_Order and add a function called getCustomerIsGuest that returns false or true instead of '0' or '1'
  • Extend Mage_Core_Model_Email_Template_Filter and replace the function ifDirective so it will treat '0' as false
2
  • To be clear: the customer_group_id workaround you describe doesn't work in my environment. Jan 2 '14 at 11:43
  • Yes, customer_group_id is stored as 0 here for guest customers as well. I'll take a deeper look and report back. Thanks for the insight!
    – Zifius
    Jan 9 '14 at 21:45

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.