Magento getAttributeText () not working in shell script

I have the following code to iterate over all products and echo noise and manufacturer, but $ manu is always empty, even if I understood sku correctly.

private function organize() { $products = Mage::getModel('catalog/product')->getCollection(); foreach ($products as $product) { $sku = $product->getSku(); $manu = $product->getAttributeText('manufacturer'); // The following also doesn't work //$manu = $product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($product); echo $sku." - ".$manu."\n"; } } 

It works like a script command line that extends from Mage_Shell_Abstract

What could be wrong with my code?

David

+1
source share
2 answers

I prefer the comment @Tim (of course, credit for it), since we do not need to do another loading of the product (it automatically loads when we make foreach from our collection)

The manufacturer attribute is not automatically selected because it is not stored in the main table ( catalog_product_entity ).

 $products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('manufacturer'); 
+3
source

When iterating through a collection, EAV attributes are not loaded. Try instead:

 $products = Mage::getModel('catalog/product')->getCollection(); foreach ($products->getAllIds() as $productId) { $product = Mage::getModel('catalog/product'); $product->load($productId); $sku = $product->getSku(); $manu = $product->getAttributeText('manufacturer'); echo $sku." - ".$manu."\n"; } 
-1
source

Source: https://habr.com/ru/post/902098/


All Articles