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.

Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182
SR_Magento
  • 5,209
  • 13
  • 62
  • 103

2 Answers2

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.

Sander Mangel
  • 37,528
  • 5
  • 80
  • 148
3

You can get the id with

$_item->getProductId();

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

Marius
  • 197,939
  • 53
  • 422
  • 830