开发者

Pull specific category in Magento and only return configurables

I am trying to develop a module that only loops through one category and shows those products. The following code does that, however it will pull the product for every size that is in that category. Can someone help me modify it to only pull the configurables? The code I am using is something like:

$my_category_id ="12";
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description'), 'inner')
->addCategoryFilter(Mage::getModel('catalog/category')->load($my_category_id));

and the loop is like :

  <?php $i=0; foreach ($_productCollection as $_product): ?>
    <?php if($_product->isSaleable()): ?>

       <img class="<?php echo $_product->getId() ?>"  src="<?php echo $this->helper('catalog/image')-&g开发者_运维知识库t;init($_product, 'small_image')->resize(150, 100); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />

    <?php else : ?>
    <?php endif; ?>
  <?php endforeach ?>


Add the following to your project collection:

->addAttributeToFilter('type_id', array('eq' => Mage_Catalog_Model_Product_Type::CONFIGURABLE));


try this

$my_category_id ="12"; $_productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect(array('name','price','small_image','short_description'), 'inner') ->addAttributeToFilter('type_id',array('eq'=>Mage_Catalog_Model_Product_Type::CONFIGURABLE)) ->addCategoryFilter(Mage::getModel('catalog/category')->load($my_category_id));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜