6

I want to change the attribute set of Magento. I searched through, and everyone suggested to delete the product and re-import it with new attribute set.

I did the same however after importing the data I could not see product reviews and associated blog post with product.

Can anyone tell me is it possible to get product reviews and associated blog post after re-importing the product with new attribute set.

Mike
  • 2,132
  • 3
  • 20
  • 33
Satyendra Mishra
  • 523
  • 2
  • 9
  • 21

6 Answers6

12

Once set you can't change the attribute set of a product. But it's possible using this module so you don't have to reimport your data.

EDIT: The module is no longer available on the Magento Marketplace website. See the GitHub page: https://github.com/flagbit/Magento-ChangeAttributeSet

HenryHayes
  • 368
  • 2
  • 4
  • 13
mtwde
  • 289
  • 1
  • 5
  • 3
    omg magento, seriously. how many decades have you been around, and you still make stuff like this so cumbersome – ahnbizcad May 02 '17 at 16:51
5

It's also possible to change the attribute set directly in the database.

  • Look up the attribute set ID in table eav_attribute_set
  • Change the attribute set ID in catalog_product_entity

Of course, be careful when changing data this way.

scrowler
  • 24,273
  • 9
  • 60
  • 92
dmaij
  • 1,017
  • 7
  • 15
  • What are the flow on effects of this? Does the ID have to be changed in the EAV attribute tables e.g. varchar that reference it too? – scrowler Oct 18 '15 at 22:35
  • UPDATE `catalog_product_entity` SET `attribute_set_id` = '9' WHERE `catalog_product_entity`.`entity_id` = 15,14; what is the error in this code, for single id its working, when i add more than one its not update. – Gem Nov 17 '17 at 06:02
  • shouldnt = replace with in(15,14) – Boss Nass Feb 03 '19 at 05:44
2

It is fiddly to do and a bit messy:

  • Make sure new attribute set is set up
  • Export the products you want to change
  • Delete the products that you are changing on the site
  • Change the attribute set on the downloaded file
  • Import changed file again
  • Open each changed product, set their attribute values, save it

Or do what I do, install this great extension from Amasty http://amasty.com/mass-product-actions.html - it makes changing a breeze and gives many more time saving and enhancing options.

darrylxxx
  • 21
  • 1
1

Once you delete the product you can't get the old review.

You don't need to delete the product . You can change the attribute set by editing and use. other wise create a new attribute set and create new product.

0

Yes. We can change product attribute set programmatically. I prefer to create massaction in catalog product grid to multiselect product and then select massaction for the products.

Creating massaction in grid.php

$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
                ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
                ->load()
                ->toOptionHash();

$this->getMassactionBlock()->addItem('changeattributeset', array(
                'label'=> Mage::helper('catalog')->__('Change attribute set'),
                'url'  => $block->getUrl('*/*/changeattributeset', array('_current'=>true)),
                'additional' => array(
                    'visibility' => array(
                        'name' => 'attribute_set',
                        'type' => 'select',
                        'class' => 'required-entry',
                        'label' => Mage::helper('catalog')->__('Attribute Set'),
                        'values' => $sets
                    )
                )
            )); 

Creating controller action for change attribute sets of the selected products.

public function changeattributesetAction()
{
    $productIds = $this->getRequest()->getParam('product');
    $storeId = (int)$this->getRequest()->getParam('store', 0);
    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();
            }
            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());
}
Kazim Noorani
  • 263
  • 3
  • 6
0

You can add to your data patch apply function something like this:

public function apply(): self
{
    $this->moduleDataSetup->getConnection()->startSetup();
    /** @var EavSetup $eavSetup */
    $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);


    $eavSetup->addAttributeToSet(
        Product::ENTITY,
        'Default',
        'General',
        CustomAttributesInterface::ATTRIBUTE_CODE_MANUFACTURER
    );
    
    $this->moduleDataSetup->getConnection()->endSetup();

    return $this;
}

This changes the manufacturer products attribute to the Default attribute set. (By default this attribute has no attribute set.) Hope it helps :)