检查Magento产品是否为可配置产品的子级 [英] Checking if a Magento product is a child of a configurable product
问题描述
我有以下代码来获取产品列表
I have the following code to grab a list of Products
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name')
->addAttributeToFilter("category_ids", array('finset'=>$this->category_id));
foreach($collection as $product) {
echo $product->getName();
}
我的问题是,我如何不回显简单"但属于父级可配置"产品的产品. (例如,不要显示"Red Shirt Medium",因为它属于"Red Shirt")
My question is, how can I NOT echo products that are 'simple' but belong to a parent 'configurable' product. (for example don't show "Red Shirt Medium" as it belongs to "Red Shirt")
我已经知道该关联位于"catalog_product_super_link
"中,但是我才刚刚开始使用Magento,不幸的是不知道如何进行过滤:)
I have worked out that this association lives in 'catalog_product_super_link
' but I have only just started with Magento and unfortuantely don't know how to do the filtering :)
干杯们,
克里斯.
推荐答案
我不知道将这种条件添加到集合中的直接方法,我也对这种解决方案感兴趣.但是您始终可以在循环中检查每种产品:
I don't know a direct way to add this condition to the collection, I'd be interested in such a solution too. But you can always check inside the loop for each product:
if (empty(Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId())))
{
echo $product->getName();
}
这篇关于检查Magento产品是否为可配置产品的子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!