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";
};
Comments
-
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'
andProduct type='Simple Product'
notattribute set='Default'
andProduct type='configurable Product'
. -
Poles almost 10 yearsyou 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 almost 10 yearsare you want simple Products with default attribute set of a configurable Product???
-
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 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_type_configurable') ->getParentIdsByChild($childId); if(!empty($ConfigProduct)){ // childId is simple product of Configuration })
-
Poles almost 10 yearsThanks @Spars. I also developed the same logic in the mean time.