Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento collection iterator - cannot get additional attribute

I can't get additional attribute 'name' from product collection when I'm using resource iterator.

My product collection:

        $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');

Iterator:

Mage::getSingleton('core/resource_iterator')->walk($productCollection->getSelect(), array(array($this, 'generateXml')));

generateXml function:

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"
}

Thanks in advance.

like image 366
Krzysztof Avatar asked Jan 10 '23 06:01

Krzysztof


1 Answers

Instead:

(...)
$productCollection->addAttributeToSelect('name')
(...)

should be:

(...)
$productCollection->addAttributeToSelect(array('name'),'inner')
(...)
like image 194
Krzysztof Avatar answered Jan 31 '23 06:01

Krzysztof