<?php Mage::register('isSecureArea', 1); Mage::app()->setUpdateMode(false); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $installer = $this; $installer->startSetup(); $setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup'); $setup->startSetup(); $setup->addAttribute('catalog_category', 'top_menu', array('group' => 'General Information', 'input' => 'select', 'source' => 'eav/entity_attribute_source_boolean', 'type' => 'int', 'label' => 'Top menu', 'backend' => '', 'visible' => true, 'required' => false, 'wysiwyg_enabled' => false, 'visible_on_front' => false, 'is_html_allowed_on_front' => false, 'default' => 1, 'sort_order' => '999', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL)); $topCategories = array(86, 87, 93, 95, 110); foreach ($topCategories as $categoryId) { $category = Mage::getModel('catalog/category')->load($categoryId); $category->setTopMenu(Mage_Eav_Model_Entity_Attribute_Source_Boolean::VALUE_YES)->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->save(); } $setup->endSetup(); $installer->endSetup();
<?php /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */ //$installer = $this; $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup'); $installer->startSetup(); // is product used for recurring payments $installer->addAttribute('catalog_product', 'is_wrapable', array('group' => 'General', 'type' => 'int', 'backend' => '', 'frontend' => '', 'label' => 'Enable Wrapable Product', 'note' => 'Add Gift Wrap feature to this product or not.', 'input' => 'select', 'class' => '', 'source' => 'eav/entity_attribute_source_boolean', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'unique' => false, 'apply_to' => 'simple,virtual,bundle,configurable,grouped', 'is_configurable' => false)); $installer->endSetup();
public function import($is_update) { $write = $this->_getWriteAdapter(); $write->beginTransaction(); $fileName = $_FILES['csv_brand']['tmp_name']; $csvObject = new Varien_File_Csv(); $csvData = $csvObject->getData($fileName); $number = array('insert' => 0, 'update' => 0); $brandUpdate = array(); /** checks columns */ $csvFields = array(0 => 'Name', 1 => 'Sort Order', 2 => 'URL Key', 3 => 'Page Title', 4 => 'Is Featured', 5 => 'Status', 6 => 'Short Description', 7 => 'Description', 8 => 'Meta Keywords', 9 => 'Meta Description'); $resource = Mage::getSingleton('core/resource'); $read = $resource->getConnection('core_read'); $brandTable = $resource->getTableName('shopbybrand/brand'); $allStores = Mage::app()->getStores(); $lastbrandId = Mage::getModel('shopbybrand/brand')->getCollection()->addFieldtoSelect('brand_id')->getLastItem()->getId(); if ($csvData[0] == $csvFields) { $arrayUpdate = $this->csvGetArrName($csvData); $prefix = Mage::helper('shopbybrand')->getTablePrefix(); $attributeCode = Mage::helper('shopbybrand/brand')->getAttributeCode(); $attributeId = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode)->getId(); $setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('catalog_setup'); $option['attribute_id'] = $attributeId; $optionId = 0; try { foreach ($csvData as $k => $v) { if ($k == 0) { continue; } //end of file has more then one empty lines if (count($v) <= 1 && !strlen($v[0])) { continue; } if (!empty($v[0])) { $data = array('name' => trim(preg_replace('/[^\\w\\s-]/', '', $v[0])), 'position_brand' => is_numeric($v[1]) ? $v[1] : 0, 'url_key' => Mage::helper('shopbybrand')->refineUrlKey($v[2]), 'page_title' => trim(preg_replace('/[^\\w\\s-]/', '', $v[3])), 'is_featured' => is_numeric($v[4]) ? $v[4] : 0, 'status' => is_numeric($v[5]) ? $v[5] : 0, 'short_description' => trim($v[6]), 'description' => trim($v[7]), 'meta_keywords' => trim($v[8]), 'meta_description' => trim($v[9])); if ($data['url_key'] == '') { $data['url_key'] = Mage::helper('shopbybrand')->refineUrlKey($data['name']); } if (in_array($v[0], $arrayUpdate)) { if ($is_update) { $number['update']++; $write->update($brandTable, $data, 'name = "' . $data['name'] . '"'); } continue; } $option['value']['option'][0] = $data['name']; $setup->addAttributeOption($option); if ($optionId == 0) { $select = $this->_getReadAdapter()->select()->from(array('eao' => $prefix . 'eav_attribute_option'), array('option_id', 'eaov.value', 'eaov.store_id'))->join(array('ea' => $prefix . 'eav_attribute'), 'eao.attribute_id=ea.attribute_id', array())->join(array('eaov' => $prefix . 'eav_attribute_option_value'), 'eao.option_id=eaov.option_id', array())->where('ea.attribute_code=?', $attributeCode)->where('eaov.value=?', $data['name'])->where('eaov.store_id=?', 0); $newOption = $this->_getReadAdapter()->fetchAll($select); if (count($newOption)) { $optionId = $newOption[0]['option_id']; } } else { $optionId++; } $data['option_id'] = $optionId; $dataBrand[] = $data; $number['insert']++; if (count($dataBrand) >= 200) { $write->insertMultiple($brandTable, $dataBrand); $dataBrand = array(); } } } if (!empty($dataBrand)) { $write->insertMultiple($brandTable, $dataBrand); } $write->commit(); } catch (Exception $e) { $write->rollback(); throw $e; } $setup->endSetup(); } else { Mage::throwException(Mage::helper('shopbybrand')->__('Please choose the csv file as sample to import brands.')); } return $number; }