我有以下代码来获取产品列表
$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")
我已经知道这个协会住在' catalog_product_super_link'但我刚刚开始使用Magento并且不幸的是不知道如何进行过滤:)
干杯伙计们,
克里斯.
小智 31
我不知道将这个条件添加到集合中的直接方法,我也对这样的解决方案感兴趣.但您可以随时检查每个产品的循环内容:
if (empty(Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId())))
{
    echo $product->getName();
}
我为谷歌饲料做了类似的事情.这段代码是我用来检查产品继承的:
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('*');
$products->addAttributeToFilter('status', 1);//enabled
$products->addAttributeToFilter('price', array('gt' => 0) );//price not 0
//$products->addAttributeToFilter('visibility', 4); //catalog, search - comment out to show all items (configurable products simple product breakdowns)
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
$prodIds=$products->getAllIds();
try {
foreach($prodIds as $productId) {
    $product = Mage::getModel('catalog/product');
    $product->load($productId);
    // SIMPLE PRODUCTS
    if($product->getTypeId() == 'simple' ) {
        $prodName = trim($product->getName());
        $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($productId);
        if(!$parentIds)
            $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($productId);
        if($parentIds) {    
            $parentProd = Mage::getModel('catalog/product')->load($parentIds[0]);           
            /* 
             * do something if this product has a parent or do some checks against $parentProd
             */
         } // end parent check  
    }//if SIMPLE
} // foreach
} catch(Exception $e) {
    die($e->getMessage());
}
小智 5
isConfigurable在产品类中调用了一个函数.
这可能对你有所帮助.
$product->isConfigurable(); 
// if its the parent object it'll be true, if its the child it'll be false.