Есть ли возможность добавить пользовательские атрибуты в форму регистрации клиента из панели администратора?


Я хочу создать новые поля в форме регистрации клиента. Я просто хотел узнать, есть ли возможность создать его из панели администратора Magento.

Пожалуйста, направьте меня, поскольку я новичок в magento.

Author: 7ochem, 2015-11-30

2 answers

Нет, нет возможности создать его от администратора. Для его создания вам потребуется создать собственный скрипт. Вы можете выполнить следующие действия модуля, чтобы создать пользовательский атрибут.

App/code/local/Custom/Customerattribute/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Customerattribute>
            <version>0.1.0</version>
        </Custom_Customerattribute>
    </modules>
    <global>
        <resources>
            <customerattribute_setup>
                <setup>
                    <module>Custom_Customerattribute</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </customerattribute_setup>
            <customerattribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </customerattribute_write>
            <customerattribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </customerattribute_read>
        </resources>
    </global>
</config> 

App/code/local/Custom/Customerattribute/sql/customerattribute_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "custom_attribute",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Custom Attribute",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "custom_attribute");


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

И, наконец, объявите свой модуль

App/etc/modules/Custom_Customerattribute.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Customerattribute>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Custom_Customerattribute>
  </modules>
</config>

Вы можете изменить свой код атрибута и метку в соответствии с вашими требованиями.

 2
Author: Akhilesh Patel, 2015-11-30 07:26:09

У меня нет представителя, чтобы комментировать, поэтому мне пришлось ответить.

Нет способа из панели администратора как таковой. Но вы можете сделать это на заказ

Я предполагаю, что это для magento 1. И я думаю, что этот вопрос уже обсуждался в посте: -

Http://magento.stackexchange.com/questions/5905/adding-custom-attribute-to-customer-registration-form

Вы не объяснили, это для Magento 2 или Magento 1

В том же посте Сильвен Райе поделился этой статьей кода вместе с git, откуда вы можете загрузить код для этого.

Ответ, которым он поделился: -

Чтобы разрешить публикацию атрибута в форме регистрации и на некоторых других страницах формы, вы должны установить, что атрибут(ы) доступен/доступны для этих форм.

Для этого ниже приведен пример кода для включения в настройки sql. Вы можете найти остальную часть кода, который я использовал для своего модуля имени пользователя Magento в моей учетной записи на github.

/* @var $installer Diglin_Username_Model_Entity_Setup */

$installer = $this;

/* @var $eavConfig Mage_Eav_Model_Config */

$eavConfig = Mage::getSingleton('eav/config');

$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$attributes = $installer->getAdditionalAttributes();

foreach ($attributes as $attributeCode => $data) {
    $installer->addAttribute('customer', $attributeCode, $data);

$attribute = $eavConfig->getAttribute('customer', $attributeCode);
$attribute->setWebsite( (($store->getWebsite()) ? $store->getWebsite() : 0));

if (false === ($attribute->getIsSystem() == 1 && $attribute->getIsVisible() == 0)) {
    $usedInForms = array(
        'customer_account_create',
        'customer_account_edit',
        'checkout_register',
    );
    if (!empty($data['adminhtml_only'])) {
        $usedInForms = array('adminhtml_customer');
    } else {
        $usedInForms[] = 'adminhtml_customer';
    }
    if (!empty($data['adminhtml_checkout'])) {
        $usedInForms[] = 'adminhtml_checkout';
    }

    $attribute->setData('used_in_forms', $usedInForms);
}
$attribute->save();

}

 1
Author: Envision Ecommerce, 2015-11-30 07:20:29