Como cambiar el conjunto de atributos de Magento
Por defecto en Magento no se puede cambiar el conjunto de atributos asignados a un producto, pero con muy poquito esfuerzo podemos conseguirlo.
Para esto tendremos que tocar el core de Magento por lo que siempre es recomendable hacer una copia en code/local para no tener problema con las actualizaciones.
En primer lugar tendremos que cambiar el fichero app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php y sobre la linea 253 añadir
$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
)
)
));
Luego en app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php añadimos esta nueva función
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)));
}
Con esto ya podemos acceder a los productos y desde la rejilla principal podremos cambiar el conjunto de atributos.
[/sourcecode]
Deja un comentario