当我使用资源迭代器时,无法从产品集合中获取其他属性“名称”。Magento集合迭代器 - 无法获得附加属性
我的产品集合:
$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->addAttributeToSelect('name')
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $subCategories))->addAttributeToFilter('visibility', '4')
->getSelect()->group('e.entity_id');
迭代器:
Mage::getSingleton('core/resource_iterator')->walk($productCollection->getSelect(), array(array($this, 'generateXml')));
generateXml功能:
public function generateXml($args){
var_dump($args['row']);
...
array(11) {
["entity_id"]=>
string(5) "49335"
["entity_type_id"]=>
string(1) "4"
["attribute_set_id"]=>
string(2) "18"
["type_id"]=>
string(6) "simple"
["sku"]=>
NULL
["has_options"]=>
string(1) "0"
["required_options"]=>
string(1) "0"
["created_at"]=>
string(19) "2014-05-28 19:18:49"
["updated_at"]=>
string(19) "2014-05-28 19:20:21"
["category_id"]=>
string(3) "236"
["visibility"]=>
string(1) "4"
}
在此先感谢。
终于我找到了!到目前为止我发现的所有示例都提示addAttributeToSelect('name')或addAttributeToSelect(array('name'))根本不起作用。添加一个连接类型为我解决了这个问题。一个人应该小心不要添加这么多的连接,或者性能可能会受到严重打击:-) – Saustrup
快速提示:第二个参数是$ jointype,有效值似乎是错误的,“内部”或“左边” 。 – Saustrup
我很高兴,这段代码很有用:) – Krzysztof