![]() $setup-> addAttribute( 'catalog_product', $attributeCode, $data) 'global' => Mage_Catalog_Model_Resource_Eav_Attribute:: SCOPE_STORE, If( $setup-> getAttributeId( 'catalog_product', $attributeCode)) ![]() $setup = Mage:: getResourceModel( 'catalog/setup', 'catalog_setup') ** Mage_Catalog_Model_Resource_Setup $setup */ $process = Mage:: getModel( 'index/process')-> load( $id) įunction createAttribute( $name, $attributeCode, $configurable = false, $visible = true) $installer-> updateAttribute( 'catalog_product', $attrCodeTEMP, array( 'attribute_code' => $attrCodeNEW)) Įcho " New attribute code renamed to the original attribute code\n" Rename temp attribute code to old attribute code $installer->removeAttribute('catalog_product', $attrCodeOLD) Mage:: getModel( 'catalog/product_action')-> updateAttributes( array( $_id), array( $attrCodeTEMP => $_v), 0) Įcho $_id." Saved (".memory_get_usage()." )\n" Įcho " New attribute configured successfully\n" If (empty( $myArray) or !isset( $myArray)) While (( $data = fgetcsv( $handle, 1000)) != FALSE) $allOptions = $attribute-> getSource()-> getAllOptions( true, true) $attribute = Mage:: getModel( 'eav/config')-> getAttribute( 'catalog_product', $attrCodeTEMP) //change to your attribute code running this step smoothly also on huge db Thanks to updateAttributes method we can save a lot of memory This could take a while if you have a large products catalog Import all the products values into the new attribute $aOption = $installer-> getAttributeId( $iProductEntityTypeId, $attrCodeTEMP) įor( $iCount= 0 $iCount addAttributeOption( $aOption) $iProductEntityTypeId = Mage:: getModel( 'catalog/product')-> getResource()-> getTypeId() $installer = new Mage_Eav_Model_Entity_Setup( 'core_setup') ![]() Add the unique values to the new attribute $values = $_readConnection-> fetchCol( $_query) ĬreateAttribute( $attributeOLD-> getStoreLabel(), $attrCodeTEMP, true) ĪssignToAttributeSets( $attributeOLD, $attrCodeTEMP) Įcho " New attribute assigned to attribute sets\n" $attrCodeOLD." ') AND LENGTH(TRIM(value)) > 0" $_query = " SELECT distinct value FROM catalog_product_entity_varchar WHERE attribute_id in (SELECT attribute_id FROM eav_attribute WHERE attribute_code='". $_readConnection = $_resource-> getConnection( 'core_read') $_resource = Mage:: getSingleton( 'core/resource') Get unique values to create the new attribute $data = trim( $product-> getData( $attrCodeOLD)) įputcsv( $fp, array( $product-> getId(), $data)) $collection = Mage:: getModel( 'catalog/product') in a CSV file to be imported in the new one later Collect/Export all the current old attribute values LoadB圜ode( 'catalog_product', $attrCodeOLD)
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |