Merchant Stories

Product Attributes: How To Adjust on Magento ®

Feb 9, 2015 1 min read 407 views
Listen audio
Product Attributes: How To Adjust on Magento ®

Sometimes different product groups or categories require an individual set of attributes. In this article, we will review how to change a set of attributes for existing products without additional extensions for Magento ®.

First, you need to open the file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php.

Then, locate the line $this->getMassactionBlock()->addItem(‘attributes’, array(.

You need to paste the following code above that line:

$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
      ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
      ->load()
      ->toOptionHash();
  array_unshift($statuses, array('label'=>'', 'value'=>''));
  $this->getMassactionBlock()->addItem('attribute_set', array(
       'label'=> Mage::helper('catalog')->__('Change attribute set'),
       'url'  => $this->getUrl('*/*/massAttributeSet', array('_current'=>true)),
       'additional' => array(
              'visibility' => array(
                   'name' => 'attribute_set',
                   'type' => 'select',
                   'class' => 'required-entry',
                   'label' => Mage::helper('catalog')->__('Change attribute set),
                   'values' => $sets
               )
       )
  ));

 

In order to continue modification – open the file app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php.

Locate the line ‘protected function _isAllowed()’ and paste the following code above that line:

public function massAttributeSetAction()
{
    $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()->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/', array('store'=>(int)$this->getRequest()->
    getParam('store', 0)));
}

 

After the changes in those files are saved the option ‘Change attribute set’ will appear in Catalog -> Manage products -> Actions menu and you can use it to further make the necessary changes.

If you have any problems or additional questions please feel free to consult with our experts in Magento ®.

That's where you contact us!

    By submitting this form you agree to GoMage's Terms of Use and Privacy Policy
    woo-hoo! Now its time to keep checking your inbox, as we will be getting in touch soon. Promise :)
    oops! Thanks. But it seems like some kind of technical issues stop you from meeting GOMAGE. Could you try again?