我只看到分组的产品。在我的特定产品系列中,我会过滤简单的产品。结果显示在 list.phtml 中,但作为简单的产品。我需要的是与简单产品相关的分组产品,而不是 ListView 中显示的简单产品。我不明白 Magento 的目录如何处理这个问题。
php:
public function getMySpecialProducts($maxlength=null,$minlength=null,$maxwidth=null,$minwidth=null,$maxheight=null,$minheight=null){
$products = Mage::getModel('catalog/product');
$_collection = $products->getCollection();
$_collection->addAttributeToSelect('*')
->addAttributeToFilter('size_length', array('lteq' => ''.$maxlength.''))
->addAttributeToFilter('size_length', array('gteq' => ''.$minlength.''))
->addAttributeToFilter('size_width', array('lteq' => ''.$maxwidth.''))
->addAttributeToFilter('size_width', array('gteq' => ''.$minwidth.''))
->addAttributeToFilter('size_height', array('lteq' => ''.$maxheight.''))
->addAttributeToFilter('size_height', array('gteq' => ''.$minheight.''))
->setPage(1, 10)
->addCategoryFilter($this->getMySpecialCategory())
->load();
return $_collection;
}
phtml 输出:
$_productCollection = $this->getMySpecialProducts(
$range["length"]["max"],$range["length"]["min"],
$range["width"]["max"],$range["width"]["min"],
$range["height"]["max"],$range["height"]["min"]
);
$listView = $this->getLayout()->createBlock('catalog/product_list')
->setTemplate('catalog/product/list.phtml')
->setCollection($_productCollection);
$this->getLayout()->getBlock('content')->append($listView);
echo $listView->toHTML();
感谢任何帮助。谢谢。
最佳答案
您可以尝试以下代码吗:
$collectionGrouped = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => 'grouped'));
或
// Get the grouped product a simple product belongs to
$simpleProduct->loadParentProductIds();
$parentProductIds = $simpleProduct->getParentProductIds();
或
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('type_id', array('eq' => 'grouped'))
->addAttributeToFilter('size_length', array('lteq' => ''.$maxlength.''))
->setPage(1, 10)
->addCategoryFilter($this->getMySpecialCategory())
->load();
关于php - 如何将分组的产品放入集合中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5403950/