cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a product attribute column to transactional email template?

SOLVED

How to add a product attribute column to transactional email template?

Hi guys, 

 

I want to add a product attribute to order confirmation email message as additional column just before Qty column. My product attribute code is "art". For that I copied 2 files from rwd theme to my own theme:

  • app/design/frontend/shopper/default/template/email/order/items.phtml
  • app/design/frontend/shopper/default/template/email/order/items/order/default.phtml

In items.phtml I creted new column header - it works fine. What I have to write in default.phtml file to get "art" attribute value near each ordered product? I mean a new column between SKU an Qty columns. Illustration of my task is below:

 

attribute-value-in-transactional-email-message.png

 

Magento 1.9.3.7. I was searching on Google but no one suggestion worked. I am not a professional developer so detailed answer could be very helpful for me and maybe others who face the same problem.

 

Thank you in advance!

4 REPLIES

Re: How to add a product attribute column to transactional email template?

Hi @Deivis,

 

You'll find the email template has this line:

 

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

Then, look at:

 

app/design/frontend/base/default/layout/sales.xml

And look for

 

<sales_email_order_items>

You'll find the blocks and phtml files into that definition.


Maybe you can start there.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: How to add a product attribute column to transactional email template?

Hi Damian,

 

thanks for your answer! I have checked app/design/frontend/base/default/layout/sales.xml and it shows that I use correct files for modification. Now I have to find out what exact lines I have to add to app/design/frontend/shopper/default/template/email/order/items/order/default.phtml file to get my custom product attribute "art" to the ordered products table. Below is content of default.phtml file, so you will be able to suggest an exact code lines which must be added to it.

 

<?php $_item = $this->getItem() ?>
<?php $_order = $this->getItem()->getOrder() ?>
<tbody>
    <tr>
        <td class="cell-content product-info">
        <p class="product-name"><?php echo $this->escapeHtml($_item->getName()) ?></p>
        <p class="sku"><?php echo $this->__('SKU'); ?>: <?php echo $this->escapeHtml($this->getSku($_item)) ?></p>
            <?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; ?>
                <?php $addInfoBlock = $this->getProductAdditionalInformationBlock(); ?>
                <?php if ($addInfoBlock) :?>
                    <?php echo $addInfoBlock->setItem($_item)->toHtml(); ?>
                <?php endif; ?>
                <?php echo $this->escapeHtml($_item->getDescription()) ?>
            </td>
            <td class="cell-content align-center"><?php echo $_item->getQtyOrdered()*1 ?></td>
            <td class="cell-content align-right">
                <?php if ($this->helper('tax')->displaySalesPriceExclTax($_order->getStore()) || $this->helper('tax')->displaySalesBothPrices($_order->getStore())): ?>
                    <?php if ($this->helper('tax')->displaySalesBothPrices($_order->getStore())): ?>
                        <span class="label"><?php echo Mage::helper('tax')->__('Excl. Tax'); ?>:</span>
                    <?php endif; ?>
                    <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'email', $_order->getStore())): ?>
                        <?php echo $_order->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?>
                    <?php else: ?>
                        <?php echo $_order->formatPrice($_item->getRowTotal()) ?>
                    <?php endif; ?>


                    <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                        <br />
                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'email', $_order->getStore())): ?>
                            <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount'],true,true); ?></span><br />
                                <?php endforeach; ?>
                            </small>
                        <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'email', $_order->getStore())): ?>
                            <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount'],true,true); ?></small></span><br />
                            <?php endforeach; ?>
                        <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'email', $_order->getStore())): ?>
                            <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount'],true,true); ?></span><br />
                                <?php endforeach; ?>
                            </small>
                        <?php endif; ?>

                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'email', $_order->getStore())): ?>
                            <br />
                            <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $_order->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?></span>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php endif; ?>


                <?php if ($this->helper('tax')->displaySalesPriceInclTax($_order->getStore()) || $this->helper('tax')->displaySalesBothPrices($_order->getStore())): ?>
                    <?php if ($this->helper('tax')->displaySalesBothPrices($_order->getStore())): ?>
                        <br /><span class="label"><?php echo Mage::helper('tax')->__('Incl. Tax'); ?>:</span>
                    <?php endif; ?>
                    <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
                    <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'email', $_order->getStore())): ?>
                        <?php echo $_order->formatPrice($_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
                    <?php else: ?>
                        <?php echo $_order->formatPrice($_incl-$_item->getWeeeTaxRowDisposition()) ?>
                    <?php endif; ?>
                    <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                        <br />
                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'email', $_order->getStore())): ?>
                            <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span><br />
                                <?php endforeach; ?>
                            </small>
                        <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'email', $_order->getStore())): ?>
                            <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount_incl_tax'],true,true); ?></small></span><br />
                            <?php endforeach; ?>
                        <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'email', $_order->getStore())): ?>
                            <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $_order->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span><br />
                                <?php endforeach; ?>
                            </small>
                        <?php endif; ?>

                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'email', $_order->getStore())): ?>
                            <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>:<br /> <?php echo $_order->formatPrice($_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?></span>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php endif; ?>
            </td>
        </tr>
    <?php if ($_item->getGiftMessageId() && $_giftMessage = $this->helper('giftmessage/message')->getGiftMessage($_item->getGiftMessageId())): ?>
        <tr>
            <td colspan="4" style=" border-bottom:2px solid #CCCCCC; padding:3px 9px;">
                <strong style="color:#444444; font-size:11px;"><?php echo $this->__('Gift Message') ?></strong>
                <?php echo $this->__('From:'); ?> <?php echo $this->escapeHtml($_giftMessage->getSender()) ?><br />
                <?php echo $this->__('To:'); ?> <?php echo $this->escapeHtml($_giftMessage->getRecipient()) ?><br />
                <strong><?php echo $this->__('Message:'); ?></strong><br /><?php echo $this->escapeHtml($_giftMessage->getMessage()) ?>
            </td>
        </tr>
    <?php endif; ?>
</tbody>

Thanks for your time helping me and others!

Re: How to add a product attribute column to transactional email template?

Hi @Deivis,

 

I guess you have 2 options here to add your custom attribute.

The best approach could be to add your product attribute the quote, then move the attrbiute from quote to order (order_item, of course) and then when you be at that phtml file you should be able to do somehting like:

 

<?php echo $this->escapeHtml($_item->getArt()) ?>

There is a workaround but it won't be flawless. You can use a helper on that phtml file to read the product by id and get the attribute.

This approach is faster for development but:

 

  • It won't be the true image of the product at the sale moment (becasue product attribute can change after the sale was made).
  • Could affect performance becasue you'll be doing a database read for each item.

 

I guess the first approach should be the real solution.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: How to add a product attribute column to transactional email template?

I will go for the first solution. Thank you for your professional help!