[英]Accessing custom attribute on success.phtml
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. 出于分析目的,我需要将此添加到JS中的变量并将其附加到url字符串。
Unfortunately, I can't seem to get access to the attribute and every time I try to echo the value, it returns null. 不幸的是,我似乎无法访问该属性,并且每次尝试回显该值时,它都会返回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. 我要尝试使用的主要代码在foreach中。
Any ideas why this does'nt return a value? 任何想法为什么这不返回值?
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');
}
$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. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.