php - 如何将分组的产品放入集合中

标签 php collections magento

我只看到分组的产品。在我的特定产品系列中,我会过滤简单的产品。结果显示在 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/

相关文章:

php - 德尔福 (FMX) : DCPCrypt2 in Windows produces different result in Android/IOS

ms-access - Access VBA如何从集合中删除重复项

Java:从磁盘写入/读取 map

php - 将值插入我在 Magento 数据库中创建的新字段

php - 即使密码是服务器生成的,也要散列密码?

php - MongoDB 搜索 - 自动完成

php - 无法解决 MySQL 语法中的错误 - 有效但显示错误消息

.net - 为什么没有Dictionary.TrimExcess()?

php - 如何在自定义 magento 类中调用静态方法

magento - Magento 管理面板中系统配置的空白屏幕