5

Does someone know how to check if a product is configurable ?

I want my configurable products to say 'From:' in front of the price on the product list page.

3
15

From the question it is not clear for which version you want to check still I am adding answer,

For M2 you can check like this,

if($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE){
          echo "product is configurable";
}

Where $product is \Magento\Catalog\Model\Product object


For M1 you can check like this,

if($product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE){
          echo "product is configurable";
}

Where $product is Mage_Catalog_Model_Product object

1
  • Could you please tell me how can I find the first simple product for a configurable product inside the if statement? – CodeForGood Apr 9 '20 at 9:51
3

For configurable product check product type ID using simple code.

if($_product->getTypeId() == 'configurable'){
     echo 'This is a configurable product';
}else{
     echo 'This is not a configurable product';
}

Thanks

1
  • I like your suggestion. Could you please tell me how can I find the first simple product for a configurable product inside the first if statement? – CodeForGood Apr 9 '20 at 9:49
1

For M1 you can use:

/* Mage_Catalog_Model_Product */
if ($product->isConfigurable()) {
    ...
}
1
  • Could you please tell me how can I find the first simple product for a configurable product inside the if statement? – CodeForGood Apr 9 '20 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.