Tuesday, 18 September 2012

Magento: Change Simple Product to Configurable Product

One of the big mysteries - at least to me - is why magento admin is not able to change a simple product to a configurable product.
It is obvious that this is a real world usecase!
Anyway: The guys from Flagbit GmbH delivered a free module to change the Attribute Set:

So far so good. But what is the use of a product with an different attribute set, when you still need it as configurable product.
I hacked the code. Now if you change the attribute set to 'default' then the product type is changed to 'simple'. Setting any other attribute set to the product leads to a product_type of 'configurable'.

Important: This code does not work with 'bundle' products.

What you need to do:

  • Find \app\code\community\Flagbit\ChangeAttributeSet\controllers\Adminhtml\Catalog\ProductController.php
  • Make a backup of this file
  • Find the public function changeattributesetAction()
  • Change it to:

public function changeattributesetAction()
  $productIds = $this->getRequest()->getParam('product');
  $storeId = (int)$this->getRequest()->getParam('store', 0);
    $attribute_set = $this->getRequest()->getParam('attribute_set');

    $entityTypeId = Mage::getModel('eav/entity')
    $attributeSetName = Mage::getModel('eav/entity_attribute_set')
                    ->addFieldToFilter('attribute_set_id', $attribute_set)
    if ($attributeSetName == 'Default') { $product_type = 'simple'; } else { $product_type = 'configurable'; }
  if (!is_array($productIds)) {
   $this->_getSession()->addError($this->__('Please select product(s)'));
  else {
   try {
    foreach ($productIds as $productId) {
     $product = Mage::getSingleton('catalog/product')
          $product = Mage::getSingleton('catalog/product')

    Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$productIds));
     $this->__('Total of %d record(s) were successfully updated', count($productIds))
   catch (Exception $e) {
    $this->_getSession()->addException($e, $e->getMessage());
  $this->_redirect('adminhtml/catalog_product/index/', array());

  • That's all!

Feel free to add comments.

Credits: Thanks to http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html for the syntax highlighter tutorial.