1

I have a piece of code that I am converting from magento 1 to magento 2. This is the code that has been converted

$productType = \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE;
    $bundleType = null; 
    if (null !== $mainVariationIndex) {
        $isActive = isset($item['variations'][$mainVariationIndex]['isActive']) ? $item['variations'][$mainVariationIndex]['isActive'] : false;
        if (count($item['variations']) > 1) {
            $productType = \Magento\Catalog\Model\Product\Type::TYPE_CONFIGURABLE;
        }
        if (isset($item['variations'][$mainVariationIndex]['bundleType'])) {
            $bundleType = $item['variations'][$mainVariationIndex]['bundleType'];
            $productType = $bundleType === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE ?
                \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE : \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE;
        }
    }

I am having the issue in this line

$productType = \Magento\Catalog\Model\Product\Type::TYPE_CONFIGURABLE;

The above line was like this in magento 1.9

$productType = Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;

Now when I am using the constant TYPE_CONFIGURABLE in magento 2, I am getting an error Undefined class constant. So I checked for constant in file Type.php in catalog module for magento 2 but did not find it. There were only three constants defined

const TYPE_SIMPLE = 'simple';

const TYPE_BUNDLE = 'bundle';

const TYPE_VIRTUAL = 'virtual';

So I thought it must be defined in some other file but could not find it. Now my question is should I use configurable as a string like below

$productType = 'configurable';

for my code in magento 2 or there is some other way.

1 Answer 1

3

In Magento2, we have a separate module for configurable products (vendor/module-configurable-product as Magento_ConfigurableProduct).

So you can find the text configurable from this constant & use it: \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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