如何检查产品是否是一个简单的产品

时间:2014-07-26 06:46:40

标签: magento configurable-product

我知道如何检查产品是否可配置。我还了解了如何检查简单产品是否是可配置产品的子产品。但有谁能告诉我如何检查产品是否是纯粹的简单产品?

这意味着我想检查我创建的Attribute set='Default'Product type='Simple Product'而不是attribute set='Default'Product type='configurable Product'的产品。

3 个答案:

答案 0 :(得分:3)

试试这个

$attributeSetModel = Mage::getModel("eav/entity_attribute_set")->load($product->getAttributeSetId());
$attributeSetName  = $attributeSetModel->getAttributeSetName();

$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());

if ($product->getTypeId() == 'simple' && empty($parentIds) && $attributeSetName == 'Default') {
    echo "This is a simple product with no parent configurable product in the 'Default' attribute set";
};

答案 1 :(得分:0)

我希望,您希望simple collection filter with default attributenot in configurable products child Simple Product

然后首先获取默认属性集ID

 $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
 $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->setEntityTypeFilter($entityType->getId());
$collection->addFieldToFilter('attribute_set_name','Default');
$attrbuteSetId= $collection->getFirstItem()->getId();

过滤后的产品Collection with simple product type and of non default Attribute set

$productCollection=Mage::getModel('catalog/product')->getCollection()
                        ->addAttributeToFilter('type_id','simple')
                        ->addAttributeToFilter('attribute_set_id',array('nin'=>$attrbuteSetId));

然后抓取Simple product ids which are used in Configurable product

$select = Mage::getSingleton('core/resource')->getConnection('core_read')
        ->select()
        ->from('catalog_product_super_link', array('product_id'))
        ->group('product_id');
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$results = $readConnection->fetchAll($select);

现在最终收藏

$productCollection->addAttributeToFilter('entity_id',array('nin'=>$results));

答案 2 :(得分:0)

<?php if( $_product->getTypeId() == 'simple' ): ?>
//your code for simple products 
<?php endif; ?>