在 Magento 中拉取特定类别并仅返回可配置项
我正在尝试开发一个仅循环一个类别并显示这些产品的模块。以下代码执行此操作,但它将提取该类别中每个尺寸的产品。有人可以帮我修改它以仅提取可配置项吗?我正在使用的代码类似于:
$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));
循环类似于:
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if($_product->isSaleable()): ?>
<img class="<?php echo $_product->getId() ?>" src="<?php echo $this->helper('catalog/image')->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 ?>
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')->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 ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将以下内容添加到您的项目集合中:
Add the following to your project collection:
试试这个
$my_category_id ="12";
$_productCollection = Mage::getResourceModel('目录/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('目录/类别')->load($my_category_id));
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));