Magento Forum

Page 1 of 5
Howto: Add support for changing a product attribute set
 
thirty4
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-02-28
 

In app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php around line 253 add

$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')->__('Attribute Set'),
                         
'values' => $sets
                     
)
             )
        ));

and in app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php anywhere in the class add a new function

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)));
    
}

You should now be able to select products in the grid using the check box and in the actions dropdown select “Change attribute set” and select a new attribute set then press submit.

 
Magento Community Magento Community
Magento Community
Magento Community
 
traviswu
Member
 
Total Posts:  31
Joined:  2008-05-29
 

Thank you !! this worked perfectly for me. : )

 
Magento Community Magento Community
Magento Community
Magento Community
 
atlasit
Member
 
Avatar
Total Posts:  40
Joined:  2008-06-03
Los Angeles, CA
 

it’s beautiful damian.  This would have been an awkward hurdle to work around.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fourthsyde
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2008-06-23
Peterborough, ON
 

so this will allow you to change a group of products to a new set of attributes? or add another attribute to them?

 
Magento Community Magento Community
Magento Community
Magento Community
 
XPSM1730
Member
 
Total Posts:  70
Joined:  2008-02-27
 

Thank you Damian, it worked for me smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
bmartus
Sr. Member
 
Total Posts:  128
Joined:  2008-05-22
Greenville, TX
 

To keep my changes out of the core Magento code, I wanted to copy :

app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

to

app/code/local/Mage/Adminhtml/controllers/Catalog/ProductController.php
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

The Grid.php changes have taken just fine, I can see the changes on the front end.  The controller override doesn’t seem to be loaded from the local tree (an error_log() shows the core version still being loaded, not the local) .. can we override the controllers files like this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
chickc
Jr. Member
 
Total Posts:  6
Joined:  2008-05-20
 

I tried it an got an error message. Does anyone know if this has been included in the very latest app updates?

This is a very important function.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bmartus
Sr. Member
 
Total Posts:  128
Joined:  2008-05-22
Greenville, TX
 

It’d be nice if this was brought into the core Magento system .. it’s very handy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chickc
Jr. Member
 
Total Posts:  6
Joined:  2008-05-20
 

Brandon. Were you able to get it to work? I saw the front end as well, but an error 404 when trying to execute.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bmartus
Sr. Member
 
Total Posts:  128
Joined:  2008-05-22
Greenville, TX
 

I had it working in 1.1.1 .. haven’t re-applied it since then.  Been busy with other things ..

 
Magento Community Magento Community
Magento Community
Magento Community
 
chickc
Jr. Member
 
Total Posts:  6
Joined:  2008-05-20
 

ok, thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kkoepke
Member
 
Avatar
Total Posts:  41
Joined:  2008-06-20
Stralsund/Germany
 

Many thanks. working fine with 1.1.3

 
Magento Community Magento Community
Magento Community
Magento Community
 
pilch
Jr. Member
 
Total Posts:  23
Joined:  2008-02-14
Westcountry, UK
 

Having just cloned (Duplicated in Magento ‘Product’ speak) I realised I wanted to move it out of the attribute set it was in, so this custom bit of code damian34 is awesome, thanks very much.

Two things of note.

a) I will have to remember to make a note of files I’ve changed because I’m assuming if user ‘alterations’ to code don’t get included in future releases any changes will be overwritten when we upgrade.  What do others do here when it comes to that?

b) I didn’t notice the lcoation of the select (drop-down box) for the Action field to start with.  I was looking along to the far right hand side colum which is labelled as Action, but there’s only one option as we all know and that’s to Edit.  Once I noticed the new controls, upon using them it worked flawlessly!

Regards,

Rich.

 
Magento Community Magento Community
Magento Community
Magento Community
 
DDMAN
Sr. Member
 
Total Posts:  179
Joined:  2008-01-08
 
kkoepke - 16 August 2008 02:24 AM

Many thanks. working fine with 1.1.3

@kkoepke

I added this code to my local code and I am getting the 404 error when I try to run it. I’m running the latest version 1.1.3

Did you get it to work in local code or did you keep it in the core code when using this on version 1.1.3

Thanks let me know what you did to get it to work in local code if this is the case

 
Magento Community Magento Community
Magento Community
Magento Community
 
thirty4
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-02-28
 

Have been unable to get it to work in local too, did try it as a module to override the base class with an extended class which did work but because of the nature of how to implement custom overridden controllers I was unable to get the redirect after the update to go back properly so didn’t bother trying to figure it out.

Just re-applied to 1.1.3 so it would be nice if it was added in to the core code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
DDMAN
Sr. Member
 
Total Posts:  179
Joined:  2008-01-08
 

thanks damian34

I’ll go ahead and move it back into core and just reapply after update if needed. It doesn’t affect the core functionality of the frontend so I’m ok doing that

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 5