0

我正在尝试通过 Mage_Sales_Model_Order.php 中的自定义属性访问特定产品的处理时间$handlingtime = $this->getProduct()->getAttributeText('fig_handling_time');

但是每次我发送订单电子邮件时都会收到错误消息Fatal error: Call to a member function getAttributeText() on a non-object in /home/japena/public_html/app/code/local/Mage/Sales/Model/Order.php on line 1320

我整天都在研究,尝试了许多不同的代码,得出的结论是我无法访问该产品$this->getProduct(),或者Mage::getModel('catalog/product')我也尝试过

$_product = Mage::getModel("catalog/product")->load($_product->getId()); $handlingtime = $_product->getData('fig_handling_time');

$product = Mage::getModel('catalog/product')->load($item->getId()); $handlingtime = $product->getAttributeText('fig_handling_time');

$handlingtime = Mage::getModel('catalog/product')->load($_item['product_id'])->getAttributeText('fig_handling_time');

$handlingtime = Mage::getModel('catalog/product')->load($product_id)->getAttributeText('fig_handling_time');

似乎没有任何想法能奏效,我将不胜感激。

4

1 回答 1

0

//首先获取属性id

$audienceAttributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','session_audience');
//Now Load the attribute
$audienceAttribute = Mage::getModel('catalog/resource_eav_attribute')->load($audienceAttributeId);

//现在获取您要用于对其属性值进行微调的产品集合。//我只想要分组产品的属性值。您可以添加类别过滤器等

$productCollection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter(Mage::app()->getStore())
->addAttributeToSelect('session_audience')
->addAttributeToSort('session_audience', 'asc')
->addAttributeToFilter('type_id', array('eq' => 'grouped'));

//现在获取集合的产品ID

$productCollectionIds = $productCollection ->getAllIds();

//现在我们查询数据库以获取给定产品ID的属性值。//注意我是从 catalog_product_entity_varchar 表中选择的,因为这是我使用的属性类型。

$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $read->select();
$select->from('catalog_product_entity_varchar')
->where('attribute_id = ?', $audienceAttributeId)
->where('entity_id IN (?)', $productCollectionIds );

//print_r($select->__toString());die();

//Now get the ids for the attribute values.

$result = $read->query($select);
$attributeOptionIds = array();
while($row = $result->fetch()){
$attributeOptionIds = array_merge($attributeOptionIds, explode(',', $row['value']));
}
array_unique($attributeOptionIds);
//print_r($audienceOptions);die();

//现在以集合的形式获取 Id 的实际值并对这些值进行处理。

$filteredAudienceCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($audienceAttributeId)
->setStoreFilter($audienceAttribute->getStoreId())
->addFieldToFilter('main_table.option_id', array('in' => $attributeOptionIds))
->load();
于 2013-08-02T06:10:16.523 回答