Php 访问success.phtml上的自定义属性

Php 访问success.phtml上的自定义属性,php,magento,e-commerce,Php,Magento,E Commerce,我创建了一个自定义属性来跟踪每个项目的利润 出于分析目的,我需要将其添加到JS中的变量中,并将其附加到url字符串中 不幸的是,我似乎无法访问该属性,每次尝试回显该值时,它都返回null 这是代码 $orderObj = Mage::getModel(’sales/order’)->loadByIncrementId($this->getOrderId()); $orderItems = $orderObj->getAllItems(); $basket = ‘’; $m

我创建了一个自定义属性来跟踪每个项目的利润

出于分析目的,我需要将其添加到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中

你知道为什么这个不返回值吗?

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

希望这一定会对你有所帮助

这是可行的解决方案,非常简单,但我不明白:

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

希望这一定会对您有所帮助。

试试看

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


查证details@PI.pls如果我的答案对你有用的话,别忘了接受并投票支持我的答案。这样有人可以信任我,并把它用于未来的目的。嗨,伙计,我试过这些,但它们似乎不起作用,你能不能提供一把小提琴,上面将如何集成到我提供的代码中?你可以将它添加到你的块成功phtml或你的自定义块它一定会工作的伴侣。查证details@PI.pls如果我的答案对你有用的话,别忘了接受并投票支持我的答案。这样有人可以信任我,并把它用于未来的目的。嗨,伙计,我试过这些,但它们似乎不起作用,请你提供一个如何将上述内容集成到我提供的代码中的小摆设好吗?你可以将它添加到你的block for success phtml或你的自定义block it's work mate中。看一看@我现在已经让它工作了。似乎如果我将getAttributeText更改为getData,它将返回正确的值。谢谢你朝着正确的方向努力看一看,我现在已经开始工作了。似乎如果我将getAttributeText更改为getData,它将返回正确的值。谢谢你朝着正确的方向努力