How to check if a product is a simple product

10,008

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";
};
Share:
10,008
Poles
Author by

Poles

Trying to change the world.

Updated on June 04, 2022

Comments

  • Poles
    Poles almost 2 years

    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'.

  • Poles
    Poles almost 10 years
    you didn't understand my question I don't want child of configurable products or a configurable product. I just want simple product with default attribute set
  • Amit Bera
    Amit Bera almost 10 years
    are you want simple Products with default attribute set of a configurable Product???
  • Poles
    Poles almost 10 years
    @Karlis: yeah its returns simple product but this code also returns the child product of a configurable product.
  • Kārlis Millers
    Kārlis Millers almost 10 years
    @Poles Try compare my and amit Bera answers. Take my answer in first if block, then put second if block ($childId=12;//simple Product id; $ConfigProduct=Mage::getResourceSingleton('catalog/product_t‌​ype_configurable') ->getParentIdsByChild($childId); if(!empty($ConfigProduct)){ // childId is simple product of Configuration })
  • Poles
    Poles almost 10 years
    Thanks @Spars. I also developed the same logic in the mean time.