1

I have a custom attribute which i created to track the profit of each item.

For analytical purposes, I need to add this to a variable in JS and append it to a url string.

Unfortunately, I can’t seem to get access to the attribute and every time I try to echo the value, it returns null.

Here is the code;

$orderObj = Mage::getModel(’sales/order’)->loadByIncrementId($this->getOrderId()); 
$orderItems = $orderObj->getAllItems(); 
$basket = ‘’; 
$mail_body = ‘’; 
foreach($orderItems as $item) 
{ 
$basket .= $item->getSku() .’|’. number_format($item->getRowTotal(), 2, ‘.’, ‘,’) .’|’. round($item->getQtyOrdered()) . ‘,’; 
}

foreach($orderItems as $item) { 
$product_item = Mage::getModel(’catalog/product’)->load($this->getProductId()); 
$mail_body .= $product_item->getAttributeText(’profit’); 
$mail_body .= “---\n\n”; 
}

the main code which I am trying to get to work is in the foreach.

Any ideas why this does’nt return a value?

liyakat
  • 11,825
  • 2
  • 40
  • 46
PI.
  • 1,658
  • 4
  • 19
  • 33

2 Answers2

1

Try

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();

foreach($items as $item){
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
  echo $product->getAttributeText('profit');
}
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • Take a look @ http://stackoverflow.com/questions/6924226/magento-product-attribute-get-value – MagePal Extensions Sep 16 '13 at 14:48
  • I have now got it working. Seems like if I chane getAttributeText to getData, it returns the correct value. Thanks for the push in the right direction – PI. Sep 16 '13 at 15:18
0
$custom = Mage::getModel('catalog/product')->load($item->getProductId());

echo $custom->getAttributeText('profit');

OR

This is the working solution, it's so simple, yet I don't understand:

<?php
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
echo $custom->getAttributeText('profit');
?>

hope this will sure help you.

liyakat
  • 11,825
  • 2
  • 40
  • 46
  • http://stackoverflow.com/questions/3927685/magento-checkout-success-page-product-price-and-sku-retrival check for details – liyakat Sep 16 '13 at 11:55
  • @PI.pls dont forget to accept and vote up my answer if is useful to you.so someone can trust and use it for future purpose – liyakat Sep 16 '13 at 12:15
  • Hi mate, I have tried these but they dont seem to work, could you please provide a fiddle of how the above would be integrated into the code I have provided? – PI. Sep 16 '13 at 12:56
  • you can add it to your block for success phtml or your custom block it will sure work mate. – liyakat Sep 16 '13 at 15:06