簡體   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