これに8時間頭をぶつけてきました...
顧客登録時に追加の属性を要求する必要があります(つまり、私の会社はB2Bです)。もちろん、Magentoはこれをネイティブに実行しないため、非常に複雑なビルドパスを強制的に実行します。これを行うためのモジュールを購入しましたが、コードが非常に混乱していることがわかりました(単に機能しないことは言うまでもありません)。
なんでもいい。私は自分で転がすだけだと思います。
それで、私は明確で要領を得たように見えるチュートリアルを見つけました。だから私は、それをまとめるのに数分を費やします。そして....何も。
さらにgoogle-fuは、その余分なホットウィズダムソースのために
私をこことここに導きます。
これが私が持っているものです(Magento Professional v1.11を実行しています):
ファイル構造:
WACI
- Customer
-- etc
--- config.xml
-- Model
--- Resource
---- Eav
----- Mysql4
------ Setup.php
-- sql
--- customer_setup
---- mysql4-install-0.1.0.php
etc / modules / WACI_All.xml
<config>
<modules>
<WACI_Customer>
<active>true</active>
<codePool>local</codePool>
</WACI_Customer>
</modules>
</config>
config.xml
<config>
<modules>
<WACI_Customer>
<version>0.1.0</version>
</WACI_Customer>
</modules>
<global>
<fieldsets>
<customer_account>
<title><create>1</create><update>1</update></title>
<phone><create>1</create><update>1</update></phone>
<agency><create>1</create><update>1</update></agency>
<fed_id><create>1</create><update>1</update></fed_id>
<ubi><create>1</create><update>1</update></ubi>
</customer_account>
</fieldsets>
<!--<models>
<customer>
<class>WACI_Customer_Model</class>
</customer>
</models> -->
<resources>
<customer_setup>
<setup>
<module>WACI_Customer</module>
<class>WACI_Customer_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customer_setup>
<customer_write>
<connection>
<use>core_write</use>
</connection>
</customer_write>
<customer_read>
<connection>
<use>core_read</use>
</connection>
</customer_read>
</resources>
</global>
</config>
Setup.php
<?php
class WACI_Customer_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_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,
'attribute_model' => 'customer/attribute',
'attributes' => array(
'title' => array(
'type' => 'varchar',
'input' => 'text',
'label' => 'Title / Position',
'visible' => true,
'required' => false,
'position' => 63,
),
'phone' => array(
'type' => 'varchar',
'input' => 'text',
'label' => 'Telephone',
'visible' => true,
'required' => true,
'position' => 64,
),
'agency' => array(
'type' => 'varchar',
'input' => 'text',
'label' => 'Agency / Organization',
'visible' => true,
'required' => false,
'position' => 65,
),
'fed_id' => array(
'type' => 'varchar',
'input' => 'text',
'label' => 'Fed ID',
'visible' => true,
'required' => false,
'position' => 66,
),
'ubi' => array(
'type' => 'varchar',
'input' => 'text',
'label' => 'UBI',
'visible' => true,
'required' => false,
'position' => 67,
),
),
),
);
}
}
?>
mysql4-install-0.1.0.php
<?php
Mage::log('Installing WACI_Customer');
// die ( echo 'Running This Upgrade: '.get_class($this)."\n <br /> \n"; );
$installer = $this;
$installer->installEntities();
$eavConfig = Mage::getSingleton(‘eav/config’);
$attribute_title = $eavConfig->getAttribute(‘customer’, 'title');
$attribute_phone = $eavConfig->getAttribute(‘customer’, 'phone');
$attribute_agency = $eavConfig->getAttribute(‘customer’, 'agency');
$attribute_fedid = $eavConfig->getAttribute(‘customer’, 'fed_id');
$attribute_ubi = $eavConfig->getAttribute(‘customer’, 'ubi');
// put into customer_form_attribute table so field will show in admin.
$attribute_title->setData(‘used_in_forms’, array(‘adminhtml_customer’));
$attribute_phone->setData(‘used_in_forms’, array(‘adminhtml_customer’));
$attribute_agency->setData(‘used_in_forms’, array(‘adminhtml_customer’));
$attribute_fedid->setData(‘used_in_forms’, array(‘adminhtml_customer’));
$attribute_ubi->setData(‘used_in_forms’, array(‘adminhtml_customer’));
?>
私がそれを正しく理解していると仮定すると、私はすべてを整えています...しかし、何も、何も、そしてそれ以上は何もありません。
特に:
- セットアップクラスを削除すると、致命的なエラーが発生するため、すべてが正常に行われていると思います。
- モジュールはadmin/system / configuration / Advanced /(有効)に表示されます。に書かれています
core_config_data
- 私はすべてのコードを取り除いて、空のコンテナー(デバッグ用のものを含む)を使用しました-インストールスクリプトは実行されません。書き込まれることはありません
core_resource
質問、それから2つの部分です:
1.インストールスクリプトの実行を妨げているのは何ですか?
2.新しい顧客属性を作成するためのロジックは適切ですか?
それがそうであると仮定すると-私はそれを登録ページ/顧客アカウント/管理者アカウントに取得することはかなり簡単なはずだと思います...
...ビールを飲みに行きます。
乾杯。
アップデート
@AlexeiYerofeyevが考えたように、customer
名前自体が問題でした。CustomerAttrに変更され、スクリプトはすぐに実行されました。
その後、モジュールはほぼ期待どおりに機能しましたが、@ benmarksのソリューションはよりクリーンに見えるので、次のように書き直しました。
config.xml 0.1.0
<global>
<resources>
<customerattr_setup>
<setup>
<module>WACI_CustomerAttr</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattr_setup>
</resources>
<fieldsets>
<customer_account>
<title><create>1</create><update>1</update></title>
<phone><create>1</create><update>1</update></phone>
<agency><create>1</create><update>1</update></agency>
<fed_id><create>1</create><update>1</update></fed_id>
<ubi><create>1</create><update>1</update></ubi>
</customer_account>
</fieldsets>
</global>
</config>
setup.php
<?php
Mage::log('Installing WACI_CustomerAttr');
echo 'Running Upgrade: '.get_class($this)."\n <br /> \n";
//die ( 'its running' );
$installer = $this;
/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer->startSetup();
$installer->addAttribute('customer','agency',
array(
'type' => 'varchar',
'label' => 'Agency / Organization',
'input' => 'text',
'required' => false,
'visible' => true,
'position' => 62,
)
);
$installer->addAttribute('customer','title',
array(
'type' => 'varchar',
'label' => 'Title / Position',
'input' => 'text',
'required' => false,
'visible' => true,
'position' => 63,
)
);
$installer->addAttribute('customer','phone',
array(
'type' => 'varchar',
'label' => 'Telephone',
'input' => 'text',
'required' => false,
'visible' => true,
'position' => 64,
)
);
$installer->addAttribute('customer','fed_id',
array(
'type' => 'varchar',
'label' => 'Fed ID',
'input' => 'text',
'required' => false,
'visible' => true,
'position' => 65,
)
);
$installer->addAttribute('customer','ubi',
array(
'type' => 'varchar',
'label' => 'UBI',
'input' => 'text',
'required' => false,
'visible' => true,
'position' => 66,
)
);
$attrs = array('agency','title','phone','fed_id','ubi');
foreach ($attrs as $item) {
$attr = Mage::getSingleton('eav/config')->getAttribute('customer', $item);
$attr->setIsUsedInForms(array('adminhtml_customer','customer_account_edit','customer_account_create'))->save();
}
$installer->endSetup();
?>
モジュール(およびバージョン)は正常に書き込まれcore_resource
、属性は正常にに追加されeav_attribute
ます。
でフィールドを呼び出すことができます
テーマ/テンプレート/顧客/フォーム/edit.phtml
<div class="input-box">
<label for="agency"><?php echo $this->__('Agency / Organization') ?><span class="required">*</span></label><br />
<input type="text" name="agency" id="agency" value="<?php echo $this->htmlEscape($this->getCustomer()->getAgency()) ?>" title="<?php echo $this->__('Agency') ?>" class="required-entry input-text" />
</div>
しかし、残念ながら、値は書き込まれていませんcustomer_entity_varchar
(これは、最終的には、私の最初のスクリプトでも同様でした。
したがって、テーブルに属性がありますが、現時点では顧客エンティティに追加されていません。
それが機能するようになったら、必要に応じて、その値を自由に読み書きできるようになるはずです。
この時点で私がどのように進むことができるかについて何か考えはありますか?
最終更新
わかりました、これはうまくいきました:
$attr->setData('used_in_forms', array('adminhtml_customer','customer_account_edit','customer_account_create'))->save();
それ以外の
$attr->setIsUsedInForms(array('adminhtml_customer','customer_account_edit','customer_account_create'))->save();
情報が必要な人のために...
配列がcustomer_form_attribute
前のコードでテーブルで更新されていなかったことがわかりました。