2012-07-09 76 views
5

我需要一個函數或某些代碼從屬性集中刪除屬性。我所知道的功能,分配屬性:Magento:以編程方式從屬性集中刪除屬性

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

或刪除屬性:

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

但屬性不應該被刪除。在AttributeSet'Default'(組'General')中不能再看到屬性。

我不覺得像任何功能:

removeAttributeFromAttributeSet() 

或某事。這樣

回答

9

你可以嘗試安裝腳本

<?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(); 
+0

這個作品刪除屬性,謝謝 – Marco 2012-07-10 06:21:59

0

現在,這是完整的代碼我使用和工程至極這裏面的代碼:

$installer = $this; 
$installer->startSetup(); 

$attributeType = 'catalog_product'; 

$attribute_set_name = 'Default'; 

$attributeCode='my_attribute'; 

$setId = $installer->getAttributeSetId('catalog_product', $attribute_set_name); 

$attributeId=$installer->getAttributeId($attributeType, $attributeCode); 

$installer->deleteTableRow('eav/entity_attribute', 'attribute_id', $attributeId, 'attribute_set_id', $setId); 

$installer->endSetup(); 
0

//它會永久刪除你的屬性。

$Attributes = array('accessories_size','accessories_type','apparel_type','author_artist','bag_luggage_type','bedding_pattern','bed_bath_type','books_music_type','camera_megapixels', 
'camera_type','coater','color','colors','cost','decor_type','ebizmarts_mark_visited','electronic_type','featured','fit','format','frame_style','gender','gendered','genre','homeware_style', 
'home_decor_type','impressions','is_sold','jewelry_type','length','lens_type','luggage_size','luggage_style','luggage_travel_style','make','manufacturer','material','model','necklace_length', 
'occasion','perfector','sample_item_1','sheet_size','shoe_size','shoe_type','size','sleeve_length','style'); 

$entityType = 'catalog_product'; 

foreach($Attributes as $index => $attrCode){ 

     $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode($entityType,$attrCode); // it return false when attribute not exist. 

     if($attributeId){ 
      Mage::getModel('catalog/product_attribute_api')->remove($attributeId);   
     } 
} 
0

下面將從屬性集中

<?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(); 
?>