问题描述
我有以下代码循环遍历所有产品并回显sku和制造商,但是$ manu始终为空,即使我确实正确获得了sku.
I have the following code to loop over all products and echo the sku and manufacturer, but $manu is always blank, even though I do get the 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";
}
}
这是从Mage_Shell_Abstract扩展的命令行脚本运行
This is running as a command line script extending from Mage_Shell_Abstract
我的代码可能出什么问题了?
What could be wrong with my code?
大卫
推荐答案
我更喜欢@Tim的评论(当然要感谢他),因为我们不需要另外加载产品(当我们加载产品时会自动加载)从我们的收藏中做foreach)
I prefer @Tim 's comment (of course credit for him) as we don't need to do another load of product (it is automatically loaded when we do foreach from our collection)
制造商属性未自动选择,因为它没有存储在主表(catalog_product_entity
)中.
The manufacturer attribute is not automatically selected as it is not stored in the main table (catalog_product_entity
).
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('manufacturer');
这篇关于Magento getAttributeText()在Shell脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!