問(wèn)題描述
我需要知道如何在頁(yè)面中顯示產(chǎn)品,例如(購(gòu)物車(chē),低于總數(shù))僅按 ID 顯示少數(shù)產(chǎn)品.例如:id 為 2、3、4 和 5 的產(chǎn)品.
<?php$categoryid = 64;$category = new Mage_Catalog_Model_Category();$category->load($categoryid);$collection = $category->getProductCollection();$collection->addAttributeToSelect('*');foreach ($collection as $_product) { ?><a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>"width="200" height="200" alt=""/></a><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName();?></a><?php } ?>
此時(shí)我可以看到每個(gè)產(chǎn)品的圖片和標(biāo)題.我需要顯示添加到購(gòu)物車(chē)和價(jià)格.
有人可以幫忙嗎?
從特定類(lèi)別獲取產(chǎn)品
$categoryIds = array(2,4);//類(lèi)別id$collection = Mage::getModel('目錄/產(chǎn)品')->getCollection()->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')->addAttributeToSelect('*')->addAttributeToFilter('category_id', array('in' => $categoryIds))
獲取特定產(chǎn)品 ID 的產(chǎn)品
$productids = array(52,62);//產(chǎn)品id$collection = Mage::getResourceModel('catalog/product_collection');$collection->addFieldToFilter('entity_id',array('in' => $productids));
然后在 phtml 中寫(xiě)這個(gè)
count() ?><?php//$_columnCount = $this->getColumnCount();?><?php $i=0;foreach ($collection 作為 $product): ?><?php if ($i++%4==0): ?><ul class="products-grid"><?php endif ?><li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"><a href="<?php echo $product->getProductUrl()?>"title="<?php echo $product->getName()?>"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(197, 167); ?>"alt="<?php echo $product->getName()?>"邊框="0"/></a><h2 class="product-name"><a href="<?php echo $product->getProductUrl()?>"title="<?php echo $product->getName()?>"><?php echo $product->getName() ?></a></h2><div class="price-box"><?php echo Mage::helper('core')->currency($product->getPrice(),true,false);?>