我正在尝试通过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');
似乎任何想法都没有用,我会很感激。
答案 0 :(得分: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();
//现在获取Ids作为集合的实际值,并对值进行处理。
$filteredAudienceCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($audienceAttributeId)
->setStoreFilter($audienceAttribute->getStoreId())
->addFieldToFilter('main_table.option_id', array('in' => $attributeOptionIds))
->load();