1

I have a requirement to replace the default value of SKU on all transactional emails with the products ID.

The only way I have found to achieve this is to modify the files associated with these transactions, one example is to perform the following modification on this file:

/store_root/app/code/design/frontend/default/store_template/template/email/order/items/order/default.phtml

Replacing this line:

<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
<?php 
        echo $Custom_Var = Mage::getModel('catalog/product')->load($_item['product_id'])
        ->getData('Id') ?>
</td>

With this line:

<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
    <?php $product = Mage::getModel('catalog/product')
        ->loadByAttribute('sku', $_item->getSku(), array('Id')); 
        echo $product->getId(); ?>
</td> 

While this does work to display the products ID, it negatively impacts the Taxes breakdown on the bottom of the page by showing incorrect tax values as well as multiple tax values on the emails that are sent to the client.

Is modifying these files the best way to replace SKU with the Product ID if so, is the best code to use?

Note: I am aware of the other files involved, I am using this one as an example.

2 Answers 2

3

You can get the id with

$_item->getProductId();

This should work even if the product is deleted after the order is placed.

1
  • Thanks Marius. Both methods worked, but your method is short and sweet.
    – SR_Magento
    Commented Feb 20, 2014 at 11:31
3

As far as I know editing the template files is the only way to accomplish what you want to achieve. Altho I haven't tested I think you don't need to load the product model, you should be able to access it using $_item->getProduct()->getId();. But as I said, haven't tested that.

2
  • Thanks for the help Sander, your method worked but the code was a little longer. I'll give you the +1 on elaborating more.
    – SR_Magento
    Commented Feb 20, 2014 at 11:35
  • Yup, looking it @Marius his answer you're right to go with his solution :) Commented Feb 20, 2014 at 11:41

Your Answer

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

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