1
votes

Based on http://www.webspeaks.in/2011/06/customize-new-order-email-template-in.html and http://www.magentocommerce.com/boards/viewthread/43928/ I created a custom email template.

However after many hours I can't figure out how to get the item's custom options to display in the email.

In the default email code (located at \app\design\frontend\base\default\template\email\order\items\order\default.phtml) there're these lines:

    <?php if ($this->getItemOptions()): ?>
    <dl style="margin:0; padding:0;">
        <?php foreach ($this->getItemOptions() as $option): ?>
        <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
        <dd style="margin:0; padding:0 0 0 9px;">
            <?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
        </dd>
        <?php endforeach; ?>
    </dl>
    <?php endif; ?>

But using that code in my .phtml dosn't show anything.

Here's my code:

<?php $_order = $this->getOrder() ?>
<?php $i=0; foreach ($_order->getAllItems() as $_item): ?><?php if($_item->getParentItem()) continue; else $i++; ?>
<?php echo $this->__('(') ?><?php echo $_item->getQtyOrdered()*1 ?><?php echo $this->__(') ') ?>
<strong><?php echo $this->htmlEscape($_item->getName()) ?></strong>
<?php echo $this->__('$') ?><?php echo number_format($_item->getRowTotal(), 2) ?>
<br />
    <?php if ($this->getItemOptions()): ?>
        <?php foreach ($this->getItemOptions() as $option): ?>
        <strong><em><small><?php echo $option['label'] ?></small></em></strong>
            <?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
        <?php endforeach; ?>
    <?php endif; ?>
<?php echo $this->__("-------------------") ?>
<br />
<?php endforeach; ?>
<br />
<?php echo $this->__('Subtotal: $') ?><?php echo number_format($_order->getSubtotal(), 2) ?>
<br />
<?php echo $this->__('Tax: $') ?><?php echo number_format($_order->getTaxAmount(), 2) ?>
<br />
<strong><?php echo $this->__('Grand Total: $') ?><?php echo number_format($_order->getGrandTotal(), 2) ?></strong>

I tried using $_item->getItemOptions()) but didn't help.

I'd really appreciate if anyone can help with the correct syntax (I hope that's all I'm missing).

Thank you.

2

2 Answers

2
votes

I know this question has been answered but, in my case it looked like an observer was interfering with the $this->getItemOptions() method.

Try replacing the following block of code in

app/design/frontend/[YOUR_PACKAGE]/[YOUR_THEME]/template/email/order/items/order/default.phtml

<?php if ($this->getItemOptions()): ?>
<dl style="margin:0; padding:0;">
    <?php foreach ($this->getItemOptions() as $option): ?>
    <dt><strong><em><?php echo $option['label'] ?></em></strong></dt>
    <dd style="margin:0; padding:0 0 0 9px;">
        <?php echo nl2br($option['value']) ?>
    </dd>
    <?php endforeach; ?>
</dl>
<?php endif; ?>

with this

    <?php if ($options = $_item->getProductOptions()): ?>
        <?php if (isset($options['options'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['options'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
        <?php if (isset($options['additional_options'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['additional_options'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
        <?php if (isset($options['attributes_info'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['attributes_info'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
    <?php endif; ?>
1
votes

After much research I discovered the solution.

The snippet above from the original code using a function getItemOptions() which in my file I can't access. So I found the location of that function as you can see here which uses the getProductOption() function. So this is my final code:

    <?php if ($options = $_item->getProductOptions()): ?>
    <?php if (isset($options['options'])): ?>
    <?php foreach ($options['options'] as $option): ?>
    <br /><strong><em><small><?php echo $option['label'] ?></small></em></strong>
        <br /><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
    <?php endforeach; ?>
    <?php endif; ?>
<?php endif; ?>

To explain a bit: In getProductOptions() are 2 arrays ["info_buyRequest"] and ["options"]. Within ["options"] are: ["label"], ["value"], ["print_value"], ["option_id"], ["option_type"], ["option_value"] and ["custom_view"]. I acquired this info by var_dump($options).

I hope this helps anyone that has the same issue I did.