Ejemplo n.º 1
0
 protected function _addAttributeToAttributeSet($attributeSetId, $attributeCode)
 {
     $setup = new \Mage_Eav_Model_Entity_Setup('core_setup');
     $attributeId = $setup->getAttributeId('catalog_product', $attributeCode);
     $attributeGroupId = $setup->getDefaultAttributeGroupId('catalog_product', $attributeSetId);
     $setup->addAttributeToSet('catalog_product', $attributeSetId, $attributeGroupId, $attributeId);
 }
<?php

$installer = $this;
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute_set_name = 'default';
$group_name = 'General';
$attribute_code = 'salepages';
$attribute_set_id = $installer->getAttributeSetId('catalog_product', $attribute_set_name);
$attribute_group_id = $installer->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
$attribute_id = $installer->getAttributeId('catalog_product', $attribute_code);
$installer->addAttributeToSet($entityTypeId = 'catalog_product', $attribute_set_id, $attribute_group_id, $attribute_id);
$installer->endSetup();
<?php

/**
 * @author Amasty Team
 * @copyright Copyright (c) 2015 Amasty (https://www.amasty.com)
 * @package Amasty_Xnotif
 */
$installer = new Mage_Eav_Model_Entity_Setup($this->_resourceName);
$installer->startSetup();
$installer->addAttribute('catalog_product', 'amxnotif_hide_alert', array('type' => 'int', 'backend' => '', 'frontend' => '', 'label' => 'Hide Stock Alert Block', '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, 'is_configurable' => false));
$attributeId = $installer->getAttributeId('catalog_product', 'amxnotif_hide_alert');
foreach ($installer->getAllAttributeSetIds('catalog_product') as $attributeSetId) {
    try {
        $attributeGroupId = $installer->getAttributeGroupId('catalog_product', $attributeSetId, 'General');
    } catch (Exception $e) {
        $attributeGroupId = $installer->getDefaultAttributeGroupId('catalog_product', $attributeSetId);
    }
    $installer->addAttributeToSet('catalog_product', $attributeSetId, $attributeGroupId, $attributeId);
}
$installer->endSetup();
Ejemplo n.º 4
0
$setup->getConnection()->dropColumn($setup->getTable("sales/order_item"), "box_id");
$setup->addAttribute("order_item", "box_id", array('type' => 'int'));
$setup->getConnection()->dropColumn($setup->getTable("sales/quote_item"), "box_id");
$setup->addAttribute("quote_item", "box_id", array('type' => 'int'));
$setup->getConnection()->dropColumn($setup->getTable("sales/order_item"), "box_sku");
$setup->addAttribute("order_item", "box_sku", array('type' => 'text'));
$setup->getConnection()->dropColumn($setup->getTable("sales/quote_item"), "box_sku");
$setup->addAttribute("quote_item", "box_sku", array('type' => 'text'));
// 4. Install Order Attributes
$setup = new Mage_Sales_Model_Mysql4_Setup();
$setup->getConnection()->dropColumn($setup->getTable("sales/order"), "subscription_id");
$setup->addAttribute("order", "subscription_id", array('type' => 'int'));
$setup->getConnection()->dropColumn($setup->getTable("sales/quote"), "subscription_id");
$setup->addAttribute("quote", "subscription_id", array('type' => 'int'));
$setup->getConnection()->dropColumn($setup->getTable("sales/order"), "ids_code");
$setup->addAttribute("order", "ids_code", array('type' => 'text'));
$setup->getConnection()->dropColumn($setup->getTable("sales/quote"), "ids_code");
$setup->addAttribute("quote", "ids_code", array('type' => 'text'));
// 5. Install Customer Attributes
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->removeAttribute('customer', 'payment_token');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'payment_token', array('input' => 'text', "type" => 'varchar', 'label' => 'Payment Token', 'visible' => 1, 'required' => 0, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL));
$setup->addAttributeToSet($entityTypeId, $attributeSetId, $attributeGroupId, 'payment_token');
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "payment_token");
$used_in_forms[] = "adminhtml_customer";
$attribute->setData("used_in_forms", $used_in_forms)->setData("is_used_for_customer_segment", true)->setData("is_system", 0)->setData("is_user_defined", 1)->setData("is_visible", 0)->setData("sort_order", 100);
$attribute->save();
$installer->endSetup();
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $addToSet = false;
         $redirectBack = $this->getRequest()->getParam('back', false);
         $model = Mage::getModel('customer/attribute');
         //            $model = Mage::getModel('catalog/entity_attribute');
         /* @var $model Mage_Catalog_Model_Entity_Attribute */
         if ($id = $this->getRequest()->getParam('attribute_id')) {
             $model->load($id);
             // entity type check
             if ($model->getEntityTypeId() != $this->_entityTypeId) {
                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('You cannot update this attribute'));
                 Mage::getSingleton('adminhtml/session')->setAttributeData($data);
                 $this->_redirect('*/*/');
                 return;
             }
             $data['attribute_code'] = $model->getAttributeCode();
             $data['is_user_defined'] = $model->getIsUserDefined();
             $data['frontend_input'] = $model->getFrontendInput();
         }
         if ('multiselectimg' == $data['frontend_input']) {
             $data['frontend_input'] = 'multiselect';
             $data['type_internal'] = 'multiselectimg';
         }
         if ('selectimg' == $data['frontend_input']) {
             $data['frontend_input'] = 'select';
             $data['type_internal'] = 'selectimg';
         }
         if (!isset($data['is_configurable'])) {
             $data['is_configurable'] = 0;
         }
         if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
             $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
         }
         $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
         if ($defaultValueField) {
             $data['default_value'] = $this->getRequest()->getParam($defaultValueField);
         }
         if (!isset($data['apply_to'])) {
             $data['apply_to'] = array();
         }
         if ('boolean' == $data['frontend_input']) {
             $data['frontend_input'] = 'select';
             $data['source_model'] = 'eav/entity_attribute_source_boolean';
         }
         if ('multiselect' == $data['frontend_input']) {
             $data['source_model'] = 'eav/entity_attribute_source_table';
         }
         $data['store_ids'] = '';
         if ($data['stores']) {
             if (is_array($data['stores'])) {
                 $data['store_ids'] = implode(',', $data['stores']);
             } else {
                 $data['store_ids'] = $data['stores'];
             }
             unset($data['stores']);
         }
         /**
          * @todo need specify relations for properties
          */
         if (isset($data['frontend_input']) && $data['frontend_input'] == 'multiselect') {
             $data['backend_model'] = 'eav/entity_attribute_backend_array';
         }
         $model->addData($data);
         if (!$id) {
             $model->setEntityTypeId($this->_entityTypeId);
             $model->setIsUserDefined(1);
             $addToSet = true;
         }
         if ($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) {
             // For creating product attribute on product page we need specify attribute set and group
             $model->setAttributeSetId($this->getRequest()->getParam('set'));
             $model->setAttributeGroupId($this->getRequest()->getParam('group'));
         }
         try {
             //                print_r($model->getData()); exit;
             $model->save();
             // saving Show on Manage Customers Grid and Show on Billing During Checkout
             $configuration = array('is_filterable_in_search' => Mage::app()->getRequest()->getPost('is_filterable_in_search'), 'used_in_product_listing' => Mage::app()->getRequest()->getPost('used_in_product_listing'), 'store_ids' => $data['store_ids']);
             $model->getResource()->saveAttributeConfiguration($model->getId(), $configuration);
             // adding attribute to set
             if ($addToSet) {
                 $setup = new Mage_Eav_Model_Entity_Setup('amcustomerattr');
                 $attrSetId = Mage::getModel('customer/customer')->getResource()->getEntityType()->getDefaultAttributeSetId();
                 $setup->addAttributeToSet('customer', $attrSetId, 'General', $model->getAttributeCode());
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('amcustomerattr')->__('Customer attribute was successfully saved'));
             /**
              * Clear translation cache because attribute labels are stored in translation
              */
             Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
             Mage::getSingleton('adminhtml/session')->setAttributeData(false);
             if ($this->getRequest()->getParam('popup')) {
                 $this->_redirect('adminhtml/catalog_product/addAttribute', array('id' => $this->getRequest()->getParam('product'), 'attribute' => $model->getId(), '_current' => true));
             } elseif ($redirectBack) {
                 $this->_redirect('*/*/edit', array('attribute_id' => $model->getId(), '_current' => true));
             } else {
                 $this->_redirect('*/*/', array());
             }
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setAttributeData($data);
             $this->_redirect('*/*/edit', array('_current' => true));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
Ejemplo n.º 6
0
 public function createLightSpeedAttributeSet()
 {
     // Find the Default Product attribute set.
     $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($this->getProductEntityTypeId()->getId())->addFieldToFilter('attribute_set_name', 'Default');
     $default_attribute_set = $collection->getFirstItem();
     // Create a attribute set called "LIGHTSPEED_PRODUCT_ATTRIBUTE_SET" based off of the Default product attribute set.
     $lightspeed_attribute_set_name = "LIGHTSPEED_PRODUCT_ATTRIBUTE_SET";
     $attrSet = Mage::getModel('eav/entity_attribute_set');
     $attrSet->setAttributeSetName($lightspeed_attribute_set_name);
     $attrSet->setEntityTypeId($this->getProductEntityTypeId()->getId());
     try {
         $attrSet->save();
     } catch (Mage_Core_Exception $e) {
         $this->_fault('filters_invalid', $e->getMessage());
     }
     $attrSet = $attrSet->initFromSkeleton($default_attribute_set->getId());
     $attrSet->save();
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     // Create a group called LIGHTSPEED_ATTRIBUTES for the
     $setup->addAttributeGroup('catalog_product', $attrSet->getId(), 'LIGHTSPEED_ATTRIBUTES');
     $attrSet->save();
     // Create the attributes to be put into the LIGHTSPEED_ATTRIBUTES group.
     $product_colour_code = 'LIGHTSPEED_PRODUCT_COLOR';
     $product_size_code = 'LIGHTSPEED_PRODUCT_SIZE';
     $this->createAttribute($product_colour_code, 'Color');
     // Colour is spelt Color, the American way.
     $this->createAttribute($product_size_code, 'Size');
     $attribute_group = $setup->getAttributeGroup('catalog_product', $attrSet->getId(), 'LIGHTSPEED_ATTRIBUTES');
     $colour_attribute = $setup->getAttribute('catalog_product', $product_colour_code);
     $size_attribute = $setup->getAttribute('catalog_product', $product_size_code);
     $attrSet->save();
     // Add attributes to attribute set.
     $setup->addAttributeToSet($entityTypeId = 'catalog_product', $attrSet->getId(), $attribute_group['attribute_group_id'], $colour_attribute['attribute_id']);
     $setup->addAttributeToSet($entityTypeId = 'catalog_product', $attrSet->getId(), $attribute_group['attribute_group_id'], $size_attribute['attribute_id']);
     return $attrSet->getId();
 }
<?php

$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_product');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
if (!$setup->getAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", "attribute_group_id")) {
    $setup->addAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", 1);
}
$attributeGroupId = $setup->getAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", "attribute_group_id");
$setup->removeAttribute('catalog_product', 'is_prepay');
$setup->addAttribute('catalog_product', 'is_prepay', array('label' => 'Is Prepay?', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'input' => 'boolean', 'type' => 'int', 'unique' => '0', 'required' => '0', 'used_in_product_listing' => '1', 'visible' => '1', 'user_defined' => '1', 'source' => 'eav/entity_attribute_source_boolean', 'note' => ''));
$setup->addAttributeToSet($entityTypeId, $attributeSetId, $attributeGroupId, 'is_prepay');
$installer->endSetup();
Ejemplo n.º 8
0
<?php

$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer->startSetup();
/**
 * Create table 'pixsubscription/subscription_type'
 */
$installer->getConnection()->dropTable($installer->getTable('pixsubscription/subscription_type'));
$table = $installer->getConnection()->newTable($installer->getTable('pixsubscription/subscription_type'))->addColumn('subscription_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Entity ID')->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 500, array(), 'Name')->addColumn('is_prepay_available', Varien_Db_Ddl_Table::TYPE_INTEGER, 1, array('unsigned' => true), 'Is prepay available');
$installer->getConnection()->createTable($table);
/**
 * Create table 'pixsubscription/subscription'
 */
$installer->getConnection()->dropTable($installer->getTable('pixsubscription/subscription'));
$table = $installer->getConnection()->newTable($installer->getTable('pixsubscription/subscription'))->addColumn('subscription_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Subscription ID')->addColumn('subscription_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Subscription Type Id')->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Customer Id')->addColumn('subscription_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'subscription_product_id')->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array('default' => null), 'Created At')->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array('default' => null), 'Updated At')->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array(), 'Status');
$installer->getConnection()->createTable($table);
Mage::getModel("pixsubscription/subscription_type")->setName("Month to Month")->setIsPrepayAvailable(0)->save();
Mage::getModel("pixsubscription/subscription_type")->setName("6 Month Plan")->setIsPrepayAvailable(1)->save();
Mage::getModel("pixsubscription/subscription_type")->setName("12 Month Plan")->setIsPrepayAvailable(1)->save();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_product');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
if (!$setup->getAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", "attribute_group_id")) {
    $setup->addAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", 1);
}
$attributeGroupId = $setup->getAttributeGroup($entityTypeId, $attributeSetId, "CandyClub Subscription", "attribute_group_id");
$setup->removeAttribute('catalog_product', 'subscription_type');
$setup->addAttribute('catalog_product', 'subscription_type', array('label' => 'Subscription Type', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'input' => 'select', 'type' => 'int', 'unique' => '0', 'required' => '0', 'used_in_product_listing' => '1', 'visible' => '1', 'user_defined' => '1', 'source' => 'pixsubscription/subscription_type_source_list', 'note' => ''));
$setup->addAttributeToSet($entityTypeId, $attributeSetId, $attributeGroupId, 'subscription_type');
$installer->endSetup();
Ejemplo n.º 9
0
<?php

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$catalogProduct = 'catalog_product';
$attributeCode = 'ism_newstoremembers_price';
$setup->addAttribute($catalogProduct, $attribute_code, array('input' => 'text', 'label' => 'Newstore Member Price', 'backend' => '', 'frontend_class' => 'validate-number', 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'searchable' => 0, 'filterable' => 0, 'sort_order' => 30, 'comparable' => 0, 'visible_on_front' => 0, 'visible_in_advanced_search' => 0, 'is_html_allowed_on_front' => 0, 'is_configurable' => 1, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL));
//add new attribute in prices attribute set
$groupName = 'prices';
$attributeSetName = 'default';
$attributeSetId = $setup->getAttributeSetId($catalogProduct, $attributeSetName);
$attributeGroupId = $setup->getAttributeGroupId($catalogProduct, $attributeSetId, $groupName);
$attributeId = $setup->getAttributeId($catalogProduct, $attributeCode);
$setup->addAttributeToSet($catalogProduct, $attributeSetId, $attributeGroupId, $attributeId);
$installer->endSetup();
$group = Mage::getModel('customer/group')->setData(array('customer_group_code' => 'Newstore Members Group', 'tax_class' => 3))->save();
Mage::getModel('core/config')->saveConfig('ism_newstore_members/newstore_members_group', "0", 'defaut', $group->getId());
Ejemplo n.º 10
0
 /**
  * Update family
  *
  * @param array $data
  *
  * @return $this
  */
 protected function _updateFamily($data)
 {
     /* @var $model Mage_Catalog_Model_Resource_Eav_Attribute */
     $model = Mage::getModel('catalog/resource_eav_attribute');
     $model->load($data['entity_id']);
     if ($model->hasData()) {
         /* @var $familyModel Pimgento_Family_Model_Import */
         $familyModel = Mage::getModel('pimgento_family/import');
         $groups = $this->getRequest()->getCodes($familyModel->getCode());
         $families = explode(',', $data['families']);
         /* Enable different group per attributeset (family)*/
         $familyGroups = explode(',', $data['group']);
         while (count($familyGroups) < count($families)) {
             $familyGroups[] = $familyGroups[0];
         }
         $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
         foreach ($families as $key => $family) {
             if (isset($groups[$family])) {
                 $groupName = ucfirst($familyGroups[$key]);
                 $setup->addAttributeGroup('catalog_product', $groups[$family], $groupName);
                 $id = $setup->getAttributeGroupId('catalog_product', $groups[$family], $groupName);
                 if ($id) {
                     $setup->addAttributeToSet('catalog_product', $groups[$family], $id, $model->getId());
                 }
             }
         }
     }
     return $this;
 }
Ejemplo n.º 11
0
<?php

$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_product', 'featured', array('type' => 'int', 'backend_type' => 'int', 'backend' => '', 'frontend' => '', 'label' => 'Is Featured', 'input' => 'boolean', 'frontend_class' => '', 'source' => 'eav/entity_attribute_source_boolean', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 'visible' => false, 'required' => false, 'user_defined' => true, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'unique' => false, 'apply_to' => '', 'is_configurable' => false));
$setup->addAttributeToSet('catalog_product', 'Default', 'General', 'featured');
$installer->endSetup();