繁体   English   中英

在success.phtml上访问自定义属性

[英]Accessing custom attribute on success.phtml

我创建了一个自定义属性,用于跟踪每个项目的利润。

出于分析目的,我需要将此添加到JS中的变量并将其附加到url字符串。

不幸的是,我似乎无法访问该属性,并且每次尝试回显该值时,它都会返回null。

这是代码;

$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”; 
}

我要尝试使用的主要代码在foreach中。

任何想法为什么这不返回值?

尝试

$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');

要么

这是有效的解决方案,它很简单,但我不明白:

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

希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM