magento:如何在捆绑产品中获取所有项目的小图像
题
我想在产品上市页面上显示捆绑产品的项目(产品)的所有图像,是否有任何Magento功能这样做,请指导我做这件事。
我创建了带有4项的捆绑产品,说a,b,c,d
现在在产品上市页面上我想显示这些产品的所有4个小_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
是一个产品对象。
这应该是工作。祝你好运。