Magento - 访问 Mage_Sales_Model_Order.php 中的产品自定义属性值

问题描述 投票:0回答:1

我正在尝试通过 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');

似乎没有什么可行的想法,我会很感激。

php magento
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();
© www.soinside.com 2019 - 2024. All rights reserved.