2日間、私は新しい顧客属性をmagentoデータベースに追加しようとしています。しかし、それは機能していません。このチュートリアルに従って、単純なnickname
入力フィールドをregister.phtml
およびedit.phtml
に追加しました。
固有のフォーラム投稿は次のとおりです。
http://www.magentocommerce.com/boards/viewthread/9620/
属性はデータベーステーブルeav_attribute
に追加されますが、値はcustomer_entity_varchar
に表示されません。
すべてのファイルはapp/code/local/Company/
の下にあります
app/code/local/Company/Customer/etc/config.xml
(気をつけてください:<!-- nickname -->
)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Company_Customer>
<version>0.1.0</version>
</Company_Customer>
</modules>
<admin>
<fieldsets>
<customer_dataflow>
<store_id><system>1</system></store_id>
<store><ignore>1</ignore></store>
<entity_id><system>1</system><ignore>1</ignore></entity_id>
<attribute_set_id><system>1</system><ignore>1</ignore></attribute_set_id>
<attribute_set><ignore>1</ignore></attribute_set>
<entity_type_id><system>1</system></entity_type_id>
<increment_id><system>1</system><ignore>1</ignore></increment_id>
<parent_id><system>1</system></parent_id>
<created_at><system>1</system></created_at>
<updated_at><system>1</system></updated_at>
<group_id><ignore>1</ignore></group_id>
<type_id><system>1</system><ignore>1</ignore></type_id>
<type><ignore>1</ignore></type>
<created_in><system>1</system><ignore>1</ignore></created_in>
<website_id><system>1</system></website_id>
<default_billing><system>1</system></default_billing>
<default_shipping><system>1</system></default_shipping>
<prefix><billing>1</billing><shipping>1</shipping><mapped>1</mapped></prefix>
<firstname><billing>1</billing><shipping>1</shipping><required>1</required><mapped>1</mapped></firstname>
<middlename><billing>1</billing><shipping>1</shipping><mapped>1</mapped></middlename>
<lastname><billing>1</billing><shipping>1</shipping><required>1</required><mapped>1</mapped></lastname>
<suffix><billing>1</billing><shipping>1</shipping><mapped>1</mapped></suffix>
<street_full><billing>1</billing><shipping>1</shipping></street_full>
<street1><street>1</street></street1>
<street2><street>1</street></street2>
<street3><street>1</street></street3>
<street4><street>1</street></street4>
<street5><street>1</street></street5>
<street6><street>1</street></street6>
<street7><street>1</street></street7>
<street8><street>1</street></street8>
<city><billing>1</billing><shipping>1</shipping></city>
<region><billing>1</billing><shipping>1</shipping></region>
<country><billing>1</billing><shipping>1</shipping><billing_required>1</billing_required><shipping_required>1</shipping_required></country>
<postcode><billing>1</billing><shipping>1</shipping><billing_required>1</billing_required><shipping_required>1</shipping_required></postcode>
<telephone><billing>1</billing><shipping>1</shipping></telephone>
<company><billing>1</billing><shipping>1</shipping></company>
<fax><billing>1</billing><shipping>1</shipping></fax>
<mobile><billing>1</billing><shipping>1</shipping></mobile>
<!-- nickname -->
<nickname><system>1</system></nickname>
</customer_dataflow>
</fieldsets>
</admin>
<global>
<fieldsets>
<customer_account>
<prefix><create>1</create><update>1</update><name>1</name></prefix>
<firstname><create>1</create><update>1</update><name>1</name></firstname>
<middlename><create>1</create><update>1</update><name>1</name></middlename>
<lastname><create>1</create><update>1</update><name>1</name></lastname>
<suffix><create>1</create><update>1</update><name>1</name></suffix>
<email><create>1</create><update>1</update></email>
<password><create>1</create></password>
<confirmation><create>1</create></confirmation>
<dob><create>1</create><update>1</update></dob>
<taxvat><create>1</create><update>1</update></taxvat>
<!-- nickname -->
<nickname><create>1</create><update>1</update></nickname>
</customer_account>
</fieldsets>
<customer>
<address>
<formats>
<text translate="title" module="customer">
<title>Text</title>
<defaultFormat><![CDATA[
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}
{{depend company}}{{var company}}{{/depend}}
{{var street1}}
{{depend street2}}{{var street2}}{{/depend}}
{{depend street3}}{{var street3}}{{/depend}}
{{depend street4}}{{var street4}}{{/depend}}
{{depend city}}{{var city}}, {{/depend}}{{depend region}}{{var region}}, {{/depend}}{{var postcode}}
{{var country}}
T: {{var telephone}}
{{depend fax}}F: {{var fax}}{{/depend}}
{{depend mobile}}M: {{var mobile}}{{/depend}}
]]></defaultFormat>
</text>
<oneline translate="title" module="customer">
<title>Text One Line</title>
<htmlEscape>true</htmlEscape>
<defaultFormat>
<![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}]]>
</defaultFormat>
</oneline>
<html translate="title" module="customer">
<title>HTML</title>
<htmlEscape>true</htmlEscape>
<defaultFormat><![CDATA[
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
{{depend company}}{{var company}}<br />{{/depend}}
{{var street1}}<br />
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{depend city}}{{var city}}, {{/depend}}{{depend region}}{{var region}}, {{/depend}}{{var postcode}}<br/>
{{var country}}<br/>
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}<br/>F: {{var fax}}{{/depend}}
{{depend mobile}}<br/>M: {{var mobile}}{{/depend}}
]]></defaultFormat>
</html>
<pdf translate="title" module="customer">
<title>PDF</title>
<defaultFormat><![CDATA[
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}|
{{depend company}}{{var company}}|{{/depend}}
{{var street1}}|
{{depend street2}}{{var street2}}|{{/depend}}
{{depend street3}}{{var street3}}|{{/depend}}
{{depend street4}}{{var street4}}|{{/depend}}
{{depend city}}{{var city}}, {{/depend}}{{depend region}}{{var region}}, {{/depend}}{{var postcode}}|
{{var country}}|
{{depend telephone}}T: {{var telephone}}{{/depend}}|
{{depend fax}}<br/>F: {{var fax}}{{/depend}}|
{{depend mobile}}<br/>M: {{var mobile}}{{/depend}}|
]]></defaultFormat>
</pdf>
<js_template template="title" module="customer">
<title>Javascript Template</title>
<defaultFormat><![CDATA[#{prefix} #{firstname} #{middlename} #{lastname} #{suffix}<br/>#{company}<br/>#{street0}<br/>#{street1}<br/>#{street2}<br/>#{street3}<br/>#{city}, #{region}, #{postcode}<br/>#{country_id}<br/>T: #{telephone}<br/>F: #{fax}<br/>M: #{mobile}]]></defaultFormat>
</js_template>
</formats>
</address>
</customer>
<models>
<customer_entity>
<rewrite>
<setup>Company_Customer_Model_Entity_Setup</setup>
</rewrite>
</customer_entity>
</models>
<resources>
<customer_setup>
<rewrite>
<setup>Company_Customer_Model_Entity_Setup</setup>
</rewrite>
</customer_setup>
</resources>
</global>
</config>
app/code/local/Company/Customer/Model/Entity/Setup.php
(もう一度気をつけてください:/* nickname */
)
class Company_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup{
public function getDefaultEntities()
{
return array(
'customer' => array(
'entity_model' =>'customer/customer',
'table' => 'customer/entity',
'increment_model' => 'eav/entity_increment_numeric',
'increment_per_store' => false,
'additional_attribute_table' => 'customer/eav_attribute',
'entity_attribute_collection' => 'customer/attribute_collection',
'attributes' => array(
// 'entity_id' => array('type'=>'static'),
// 'entity_type_id' => array('type'=>'static'),
// 'attribute_set_id' => array('type'=>'static'),
// 'increment_id' => array('type'=>'static'),
// 'created_at' => array('type'=>'static'),
// 'updated_at' => array('type'=>'static'),
// 'is_active' => array('type'=>'static'),
'website_id' => array(
'type' => 'static',
'label' => 'Associate to Website',
'input' => 'select',
'source' => 'customer/customer_attribute_source_website',
'backend' => 'customer/customer_attribute_backend_website',
'sort_order' => 10,
),
'store_id' => array(
'type' => 'static',
'label' => 'Create In',
'input' => 'select',
'source' => 'customer/customer_attribute_source_store',
'backend' => 'customer/customer_attribute_backend_store',
'visible' => false,
'sort_order' => 20,
),
'created_in' => array(
'type' => 'varchar',
'label' => 'Created From',
'sort_order' => 30,
),
'prefix' => array(
'label' => 'Prefix',
'required' => false,
'sort_order' => 37,
),
'firstname' => array(
'label' => 'First Name',
'sort_order' => 40,
),
'middlename' => array(
'label' => 'Middle Name/Initial',
'required' => false,
'sort_order' => 43,
),
'lastname' => array(
'label' => 'Last Name',
'sort_order' => 50,
),
'suffix' => array(
'label' => 'Suffix',
'required' => false,
'sort_order' => 53,
),
'email' => array(
'type' => 'static',
'label' => 'Email',
'class' => 'validate-email',
'sort_order' => 60,
), /* nickname */
'nickname' => array(
'label' => 'nickname',
'unique' => true,
'sort_order' => 65,
'required' => true,
),
'group_id' => array(
'type' => 'static',
'input' => 'select',
'label' => 'Group',
'source' => 'customer/customer_attribute_source_group',
'sort_order' => 70,
),
'dob' => array(
'type' => 'datetime',
'input' => 'date',
'backend' => 'eav/entity_attribute_backend_datetime',
'required' => false,
'label' => 'Date Of Birth',
'sort_order' => 80,
),
'password_hash' => array(
'input' => 'hidden',
'backend' => 'customer/customer_attribute_backend_password',
'required' => false,
),
'default_billing' => array(
'type' => 'int',
'visible' => false,
'required' => false,
'backend' => 'customer/customer_attribute_backend_billing',
),
'default_shipping' => array(
'type' => 'int',
'visible' => false,
'required' => false,
'backend' => 'customer/customer_attribute_backend_shipping',
),
'taxvat' => array(
'label' => 'Tax/VAT Number',
'visible' => true,
'required' => false,
),
'confirmation' => array(
'label' => 'Is Confirmed',
'visible' => false,
'required' => false,
),
'created_at' => array(
'type' => 'static',
'label' => 'Created At',
'visible' => false,
'required' => false,
'input' => 'date',
),
),
),
'customer_address'=>array(
'entity_model' =>'customer/customer_address',
'table' => 'customer/address_entity',
'additional_attribute_table' => 'customer/eav_attribute',
'entity_attribute_collection' => 'customer/address_attribute_collection',
'attributes' => array(
// 'entity_id' => array('type'=>'static'),
// 'entity_type_id' => array('type'=>'static'),
// 'attribute_set_id' => array('type'=>'static'),
// 'increment_id' => array('type'=>'static'),
// 'parent_id' => array('type'=>'static'),
// 'created_at' => array('type'=>'static'),
// 'updated_at' => array('type'=>'static'),
// 'is_active' => array('type'=>'static'),
'prefix' => array(
'label' => 'Prefix',
'required' => false,
'sort_order' => 7,
),
'firstname' => array(
'label' => 'First Name',
'sort_order' => 10,
),
'middlename' => array(
'label' => 'Middle Name/Initial',
'required' => false,
'sort_order' => 13,
),
'lastname' => array(
'label' => 'Last Name',
'sort_order' => 20,
),
'suffix' => array(
'label' => 'Suffix',
'required' => false,
'sort_order' => 23,
),
'company' => array(
'label' => 'Company',
'required' => false,
'sort_order' => 30,
),
'street' => array(
'type' => 'text',
'backend' => 'customer_entity/address_attribute_backend_street',
'input' => 'multiline',
'label' => 'Street Address',
'sort_order' => 40,
),
'city' => array(
'label' => 'City',
'sort_order' => 50,
),
'country_id' => array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Country',
'class' => 'countries',
'source' => 'customer_entity/address_attribute_source_country',
'sort_order' => 60,
),
'region' => array(
'backend' => 'customer_entity/address_attribute_backend_region',
'label' => 'State/Province',
'class' => 'regions',
'sort_order' => 70,
),
'region_id' => array(
'type' => 'int',
'input' => 'hidden',
'source' => 'customer_entity/address_attribute_source_region',
'required' => 'false',
'sort_order' => 80,
'label' => 'State/Province'
),
'postcode' => array(
'label' => 'Zip/Postal Code',
'sort_order' => 90,
),
'telephone' => array(
'label' => 'Telephone',
'sort_order' => 100,
),
'fax' => array(
'label' => 'Fax',
'required' => false,
'sort_order' => 110,
),
),
),
);
}
}
app/design/frontend/default/company/template/customer/form/register.phtml
<label for="nickname" class="required" style="margin-left: -1px;"><em>*</em><?php echo $this->__('Nickname') ?></label>
<input type="text" name="nickname" id="nickname" value="<?php echo $this->htmlEscape($this->getFormData()->getnickname()) ?>" title="<?php echo $this->__('Nickname') ?>" class="input-text required-entry" />
また、このphpコードをregister.phtmlの先頭で実行して、属性をeav_attributeこのコードは1回実行されました:
<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = 'nickname';
$settings = array (
'position' => 1,
'is_required' => 0
);
$setup->addAttribute('1', $AttrCode, $settings);
?>
app/design/frontend/default/company/template/customer/form/edit.phtml
<label for="nickname" class="required" style="margin-left: -1px;"><em>*</em><?php echo $this->__('Nickname') ?></label>
<input type="text" name="nickname" id="nickname" value="<?php echo $this->htmlEscape($this->getCustomer()->getnickname()) ?>" title="<?php echo $this->__('Nickname') ?>" class="input-text required-entry" />
また、/ var/cacheフォルダーを手動でクリアしましたが、効果はありませんでした。
他に何ができるかわからないので、どんな助けでも大歓迎です。
編集:
これが私がmagentoのルートで試したことです:
define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$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', 'nickname', array(
'input' => 'text',
'type' => 'text',
'label' => 'Nickname',
'visible' => 1,
'required' => 1,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'nickname',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'nickname');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();
$installer->endSetup();
このコードは正常に実行され、エラーメッセージなどは表示されませんが、eav_attributeテーブルに新しい属性が追加されることもありません。
私はあなたのスクリプトを編集しました、そしてそれは私のためにうまくいきました、私は今backedで新しい属性を見ることができます。
これを置き換えます:
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
これとともに:
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();