Change Magento product's attribute set.
Asked Answered
N

6

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.

Neoterism answered 13/6, 2013 at 12:14 Comment(0)
U
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

Uncivil answered 13/6, 2013 at 14:55 Comment(1)
omg magento, seriously. how many decades have you been around, and you still make stuff like this so cumbersomeNeptunium
W
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.

Webfoot answered 11/12, 2014 at 9:43 Comment(3)
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?Floor
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.Siracusa
shouldnt = replace with in(15,14)Psychotechnics
G
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.

Gemsbok answered 18/4, 2014 at 9:39 Comment(0)
C
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.

Cerebration answered 13/6, 2013 at 13:3 Comment(0)
F
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());
}
Freaky answered 11/10, 2017 at 10:6 Comment(0)
A
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 :)

Assured answered 25/10, 2022 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.