Magento将自定义属性保存到客户

时间:2015-12-15 13:34:12

标签: magento

我已将自定义属性添加到我的客户,并在我的客户表单中显示。但是当我尝试提交它时会触发错误:

magento Column not found: 1054 Unknown column in field list
     

此错误在$ customer-> save();的CustomerController中完全触发呼叫。   我查看了我的帖子,我在发布的数据中有了3个新字段

我的配置是这样的:

<config>
    <modules>
        <Company_Module>
            <version>0.1.0</version>
        </Company_Module>
    </modules>
    <global>
        <fieldsets>
            <customer_account>
                <my_id>
                    <create>1</create>
                    <update>1</update>
                </my_id>
                <adhesion_date>
                    <create>1</create>
                    <update>1</update>
                </adhesion_date>
                <favorite_shop_id>
                    <create>1</create>
                    <update>1</update>
                </favorite_shop_id>
            </customer_account>
        </fieldsets>
        <models>
            <Company_Module>
                <class>Company_Module_Model</class>
                <resourceModel>Company_Module_resource</resourceModel>
            </Company_Module>
            <Company_Module_resource>
                <class>Company_Module_Model_Resource</class>
            </Company_Module_resource>
        </models>
        <blocks>
            <Company_Module>
                <class>Company_Module_Block</class>
            </Company_Module>
        </blocks>
        <helpers>
            <Company_Module>
                <class>Company_Module_Helper</class>
            </Company_Module>
        </helpers>
        <resources>
            <Company_Module_setup>
                <setup>
                    <module>Company_Module</module>
                    <class>Company_Module_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
                <customer_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </customer_write>
                <customer_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </customer_read>
            </Company_Module_setup>
        </resources>
    </global>
</config>

我创造的成功属性是这样的:

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


/**
 * @param $attribute
 * @param $increment
 */
function setAttribute($attribute,$increment){
    $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", $increment)
    ;
    $attribute->save();
}

$installer->addAttribute("customer", "favorite_shop_id",  array(
    "type"     => "int",
    "backend"  => "",
    "label"    => "Favorite shop",
    "input"    => "select",
    "source"   => "Company_Module/eav_entity_attribute_source_customerOptions",
    "visible"  => true,
    "global"   => 0, // visible only on store
    "required" => false,
    "default"  => 0,
    "frontend" => "",
    "unique"   => false,
    "note"     => "",
    'user_defined' => true

));

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

$installer->addAttribute("customer", "my_id",  array(
    "type"     => "int",
    "backend"  => "",
    "label"    => "Module Id",
    "input"    => "text",
    "source"   => '',
    "visible"  => true,
    "global"   => 0, // visible only on store
    "required" => false,
    "default"  => 0,
    "frontend" => "",
    "unique"   => true,
    "note"     => "",
    'user_defined' => true

));

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

$installer->addAttribute("customer", "adhesion_date",  array(
    "type"     => "date",
    "backend"  => "",
    "label"    => "Adhesion date",
    "input"    => "date",
    "source"   => '',
    "visible"  => true,
    "global"   => 0, // visible only on store
    "required" => false,
    "default"  => date( Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
        strtotime('today')),
    "frontend" => "",
    "unique"   => false,
    "note"     => "",
    'user_defined' => true

));

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

$installer->endSetup();

0 个答案:

没有答案