How to check if a product is a simple product

Poles picture Poles · Jul 26, 2014 · Viewed 9.7k times · Source

I know how to check if a product is configurable or not. I also got how to check if a simple product is a child of a configurable product or not. But can anyone tell me how to check if a product is a pure simple product?

That means that I want to check those products which I created as Attribute set='Default' and Product type='Simple Product' not attribute set='Default' and Product type='configurable Product'.

Answer

Smeagol picture Smeagol · Jul 26, 2014

Try this

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