Magento 1.9 getMediaGalleryImages() return 从产品集合中清空
Magento 1.9 getMediaGalleryImages() return empty from products collection
我正在尝试从 Magento 1.9 中提取产品信息,我需要提取的属性之一是“media_gallery”,但是,我尝试了多种方法并且 none 有效远的。这是我获取产品集合的代码:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
这是我拉取媒体库的代码:
$productsArray = [];
$index = 0;
foreach ($products as $product) {
...
$productsArray[$index]["gallery"] = $product->getMediaGalleryImages();
...
}
我试过:
1) Mage::getModel('catalog/product')->load($product_id)->getMediaGalleryImages();
2) $product->load('media_gallery')->getMediaGalleryImages();
3) $attribute = $product->getResource()->getAttribute('media_gallery');
$backend = $attribute->getBackend();
$backend->afterLoad($product);
// None of those 3 approaches worked
我得到的回复是gallery: {}
这是我的产品在 Magento Admin 上的设置方式,您可以看到我在产品下确实有图片:
请帮助我,感谢您的宝贵时间!
问题是图像已保存到默认商店范围 (StoreId 0)。
尝试使用商店 ID = 0 加载您的产品数据
$product = Mage::getModel('catalog/product')->setStoreId(0)->load($Id);
根据您的代码的使用位置,它可能正在加载前端商店视图之一的数据,而不是商店 0。
我正在尝试从 Magento 1.9 中提取产品信息,我需要提取的属性之一是“media_gallery”,但是,我尝试了多种方法并且 none 有效远的。这是我获取产品集合的代码:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
这是我拉取媒体库的代码:
$productsArray = [];
$index = 0;
foreach ($products as $product) {
...
$productsArray[$index]["gallery"] = $product->getMediaGalleryImages();
...
}
我试过:
1) Mage::getModel('catalog/product')->load($product_id)->getMediaGalleryImages();
2) $product->load('media_gallery')->getMediaGalleryImages();
3) $attribute = $product->getResource()->getAttribute('media_gallery');
$backend = $attribute->getBackend();
$backend->afterLoad($product);
// None of those 3 approaches worked
我得到的回复是gallery: {}
这是我的产品在 Magento Admin 上的设置方式,您可以看到我在产品下确实有图片:
请帮助我,感谢您的宝贵时间!
问题是图像已保存到默认商店范围 (StoreId 0)。
尝试使用商店 ID = 0 加载您的产品数据
$product = Mage::getModel('catalog/product')->setStoreId(0)->load($Id);
根据您的代码的使用位置,它可能正在加载前端商店视图之一的数据,而不是商店 0。