Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Programmatically remove attribute from attribute-set

I need a function or some code to remove an attribute from a set where it is assigned to. I know the function, to assign an attribute:

$setup->addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId, $sortOrder=null)

or to remove an Attribute:

$setup->removeAttribute($entityTypeId, $code)

but the attribute should not be deleted. It must no longer be possible to see the attribute in the AttributeSet 'Default' (group 'General').

I don't find any function like:

removeAttributeFromAttributeSet()

or sth. like that

like image 571
Marco Avatar asked Jul 09 '12 14:07

Marco


2 Answers

You could try this code inside your setup script

<?php
/** @var $this Mage_Eav_Model_Entity_Setup */
$this->startSetup();

$this->deleteTableRow(
    'eav/entity_attribute', 
    'attribute_id', 
    $this->getAttributeId('catalog_product', 'attribute_code_here'), 
    'attribute_set_id', 
    $this->getAttributeSetId('catalog_product', 'Default')
);

$this->endSetup();
like image 153
Lee Saferite Avatar answered Nov 04 '22 08:11

Lee Saferite


Below will remove attribute from attributeset

<?php 
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_product');
$attributeId = $setup->getAttributeId('catalog_product', 'feature'); //feature is attribute code
$attributeSetId = $setup->getAttributeSetId($entityTypeId, 'Default');
$installer->deleteTableRow('eav/entity_attribute', 'attribute_id', $attributeId, 'attribute_set_id', $attributeSetId);                    
$installer->endSetup();
?>
like image 1
Digisha Avatar answered Nov 04 '22 09:11

Digisha