Magento 如何检查产品是否为简单产品

Magento 如何检查产品是否为简单产品,magento,configurable-product,Magento,Configurable Product,我知道如何检查产品是否可配置。我还了解了如何检查一个简单的产品是否是可配置产品的子产品。但是谁能告诉我如何检查一个产品是否是一个纯粹的简单产品 这意味着我想检查那些我创建为Attribute set='Default'和Product type='Simple Product'的产品,而不是Attribute set='Default'和Product type='configurable Product'我希望,您需要具有默认属性的简单集合过滤器,该过滤器不在可配置产品子简单产品中 $sele

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


这意味着我想检查那些我创建为
Attribute set='Default'
Product type='Simple Product'
的产品,而不是
Attribute set='Default'
Product type='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);
然后首先获取默认属性集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();
之后,使用简单产品类型和非默认属性集过滤产品
集合

$productCollection=Mage::getModel('catalog/product')->getCollection()
                        ->addAttributeToFilter('type_id','simple')
                        ->addAttributeToFilter('attribute_set_id',array('nin'=>$attrbuteSetId));
然后获取可配置产品中使用的
简单产品ID

$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));

//简单产品的代码
试试这个

$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";
};

你不明白我的问题,我不想要可配置产品的孩子或可配置产品。我只想要具有默认属性集的简单产品您想要具有可配置产品的默认属性集的简单产品吗?@Karlis:是的,它返回简单产品,但此代码也返回可配置产品的子产品。@请尝试比较my和amit Bera的答案。将我的答案放在第一个if块中,然后放在第二个if块($childId=12;//简单产品id;$ConfigProduct=Mage::getResourceSingleton('catalog/Product_type_-configurable')->getParentIdsByChild($childId);if(!empty($ConfigProduct)){//childId是配置的简单产品})谢谢@Spars。同时我也发展了同样的逻辑。