Как создать пользовательский выпадающий атрибут для клиента в magento
Я хочу создать пользовательский раскрывающийся атрибут для учетной записи клиента magento.
Для этого я использовал скрипт $installer, но он не работает для меня. Мой сценарий, как показано ниже:
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "track_device", array(
"label" => "Customer Device",
'input' => 'select',
'type' => 'int',
'required' => 0,
'user_defined' => 0,
'source' => 'eav/entity_attribute_source_table',
'option' => array('values' => array('Web', 'App'))
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "track_device");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$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", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
?>
Что-нибудь отсутствует или неправильно в этом сценарии?
Есть ли какой-либо другой способ создать пользовательский выпадающий атрибут в учетной записи клиента в magento?
3
Author: Vinaya Maheshwari, 2016-02-06
2 answers
Попробуйте это:
<?php
require_once('app/Mage.php');
Mage::app('default');
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->startSetup();
$entityTypeId = (int)$installer->getEntityTypeId('customer');
$attributeSetId = (int)$installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = (int)$installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('customer', 'track_device', array(
'type' => 'int',
'label' => 'Customer Device',
'input' => 'select',
'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
'source' => 'eav/entity_attribute_source_table',
'required' => false,
'visible' => 1,
'user_defined' => true, /* To display in frontend */
'position' => 110,
'option' => array('values' => array('Web', 'App'))
));
$installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'track_device', 100);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'track_device');
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
$oAttribute->save();
$installer->endSetup();
?>
6
Author: Abdul, 2016-11-12 12:48:22
require_once("app/Mage.php");
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
//$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'note', array(
'type' => 'text',
'label' => 'Note',
'global' => 1,
'visible' => 1,
'input' => 'textarea',
'position' => 32,
'required' => 0,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'note',
'100'
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'note');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit'));
$oAttribute->save();
$setup->endSetup();
1
Author: Shubham Khunt, 2017-08-24 10:24:44