マジェント :バンドル製品の全アイテムの小さな画像を取得する方法
質問
商品一覧ページにバンドル商品の商品画像をすべて表示したいのですが、そのためのMagento機能はありますか、方法を教えてください。
a、b、c、dの4つのアイテムをバンドルした製品を作成しました
製品リストページに、これらの製品の 4 つの small_images をすべて表示したいと思います。
どうすればいいでしょうか?
解決
これを試して:
$model= Mage::getModel('catalog/product');
//$product is a product object
if($product->getTypeId() == 'bundle'){
$bundles = $product->getTypeInstance(true)->getChildrenIds($product->getId(), false);
$item = array();
foreach($bundles as $index => $items){
foreach($items as $id){
$item[] = $id;
//break; //only get first item
//un-comment above line if you want only one (first) item.
}
}
if($item){
$child = $model
->getCollection()
->addAttributeToSelect(array('name', 'price', 'image', 'small_image'))
->addAttributeToFilter('entity_id', array('in' => $item))
->setOrder('price', 'DESC')
->load()
;
}
foreach($child as $item){
echo $item->getName();
echo "<br>";
echo '<img id="image" src="'.$this->helper('catalog/image')->init($item, 'small_image')->keepAspectRatio(true)->keepFrame(false)->resize(120, 100).'" alt="'.$_helper->productAttribute($item, $item->getName(), 'name').'"/>';
echo "<br>";
echo "<br>";
}
}
キーポイント
$product
製品オブジェクトです。
これは機能するはずです。幸運を。
所属していません magento.stackexchange