已经在我的头上敲了8个小时了...Magento。安装脚本不会运行,更不用说创建客户属性
我有需要(或更确切地说,我的公司确实是B2B)来请求额外的属性在客户注册。当然,Magento本身并没有这样做,所以我们被迫下降疯狂地令人费解构建路径使其如此。我买了一个模块来做到这一点,但发现代码是一个混乱(更不用说只是不工作)。
无论如何。我想我会推出自己的。
所以我找到了一个看起来很清楚并且重要的tutorial。所以我花了几分钟把它放在一起。没事了。
这里就是我有(运行Magento专业V1.11):
文件结构:
WACI
- Customer
-- etc
--- config.xml
-- Model
--- Resource
---- Eav
----- Mysql4
------ Setup.php
-- sql
--- customer_setup
---- mysql4-install-0.1.0.php
等/模块/ 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安装-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’));
?>
假设我理解正确,我已经掌握了一切......但没有什么,什么也没有。
值得注意的是:
- 如果我删除设置类,我得到一个致命的错误,所以我觉得一切都到位。
- 该模块显示在管理/系统/配置/高级/(启用);它被写入
core_config_data
- 我翻出所有的代码,只是使用空容器(调试的东西) - 安装脚本永远不会运行;它永远不会被写入
core_resource
问题,然后是两个部分:
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
表与现有代码得到更新。
信息上调试安装资源脚本是在这里:http://stackoverflow.com/questions/4717535/my-magento-extension-install-script-将不会运行 –
感谢阿兰 - 我绝对看透了,但没有尝试过。顺便说一句 - 我去的时候让你的细节出来,类显然已经改写了变化,它不再是不清楚的地方你(1)调试将被放置。我没有花时间弄清楚 - 但想你想知道。 (也许社区/专业/企业之间的区别?)。 – Bosworth99
你在布局上的电子书是天赐之物,顺便说一句。 – Bosworth99