2

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

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

4

3 回答 3

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";
};
于 2014-07-26T10:59:39.223 回答
0
<?php if( $_product->getTypeId() == 'simple' ): ?>
//your code for simple products 
<?php endif; ?>
于 2014-07-26T07:29:32.257 回答
0

我希望,你想要simple collection filter with default attribute 的是哪一个not in configurable products child Simple Product

然后先获取Default属性集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();

之后过滤 Product 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));
于 2014-07-26T07:16:14.353 回答