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:
http://www.magentocommerce.com/magento-connect/flagbit-change-attribute-set.html
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') ->setType('catalog_product') ->getTypeId(); $attributeSetName = Mage::getModel('eav/entity_attribute_set') ->getCollection() ->setEntityTypeFilter($entityTypeId) ->addFieldToFilter('attribute_set_id', $attribute_set) ->getFirstItem() ->getAttributeSetName(); 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') ->unsetData() ->setStoreId($storeId) ->load($productId) ->setAttributeSetId($this->getRequest()->getParam('attribute_set')) ->setIsMassupdate(true) ->save(); $product = Mage::getSingleton('catalog/product') ->unsetData() ->setStoreId($storeId) ->load($productId) ->setTypeId($product_type) ->setIsMassupdate(true) ->save(); } Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$productIds)); $this->_getSession()->addSuccess( $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.
This is neat. I've been looking for something like this. Your blog really helped me a lot.
ReplyDeleteYou are my hero! Worked perfectly.. converts simple to configurable products (with help of extension above) without any that I can see
ReplyDeleteThanks for sharing this information in very detail ,really useful .
ReplyDeleteMagento Developers
This works but after selecting associated products I end up with duplicate attributes (two dropdowns with same choices). Any ideas on how to fix that?
ReplyDeleteThats strange. Tell me more about your structure of your website, stores and languages.
DeleteWhoa--- I found it(!) under 'custom option'.... I'm not sure but perhaps that came across with migration. I'm on track to figuring this out. Thanks so much!
ReplyDeleteYou are wellcome. especially for the last part you found out by yourself. ;)
DeleteThis comment has been removed by the author.
ReplyDeleteHi Mr.Bosch,
ReplyDeleteafter i replaced the file with the code you provided, when i click "manage product" on admin, no products will show up with just a blank page. any idea why? if possible, can you upload the updated file so i can download it since i think maybe i did something wrong when replacing the code. thanks in advance, Jason
Did you have Code Compilation on? Maybe. Just try again with a backup of the orig file. And be carefull to copy the code right. This code works for 1.6.2. I am remote from my code currently, so I can't send you.
DeleteThank you so much, worked beautifully! Only problem is new configurable products are no longer searchable in frontend? Any ideas how to fix?
ReplyDeleteAre other products with this attribute found? Clear cache. Rebuild index ... the usual stuff.
DeleteYou're a legend!! Just saved me DAYS of additional work for a client. Worked perfectly for 1.7.0.2 :-)
ReplyDeleteThank you for such a great help. But i am not sure how to use it. I created two products with default attribute set. Default attribute set having 2 configurable attributes, i.e. "color" and "manufacturer". My need is if i select those both simple product and change attribute set, it should create new configurable product with selected products as associated products.
ReplyDeleteUsing your code i also need to reopen each product and set associated products manually.
Please suggest something to achieve my need.Thank you.
Hi, the code above is not supposed to handle your request. Sorry.
Delete