Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

MAGENTO 1:在MAGENTO中创建客户属性

今天,我们将讨论如何在Magento中创建自定义客户属性。此要求非常普遍,因为在社区版中,无法为客户实体创建自定义属性,即使在企业中,您应该能够通过admin创建自己的客户属性。无论如何,让我们继续创建一个简单的模块,以向客户实体添加自定义属性。

步骤1 –在您的本地文件夹下创建一个新模块,在本例中为\ app \ local \ Scommerce \ Customer。

步骤2 –使用以下代码在Scommerce_All.xml或Scommerce_Customer.xml中的etc \ modules目录中注册我们的模块-

<Scommerce_Customer>
    <active>true</active>
    <codePool>local</codePool>
</Scommerce_Customer>

步骤3 –使用以下代码在模块\ app \ local \ Scommerce \ Customer \ etc \ config.xml的etc目录下创建config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Scommerce_Customer>
            <version>0.0.1</version>
        </Scommerce_Customer>
    </modules>
    <global>
        <models>
            <scommercecustomer>
                <class>Scommerce_Customer_Model</class>
            </scommercecustomer>
        </models>
        <resources>
            <scommercecustomer_setup>
                <setup>
                    <module>Scommerce_Customer</module>
                    <class>Scommerce_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </scommercecustomer_setup>
        </resources>       
    </global>
</config>

上面的声明将帮助我们创建sql文件来创建新属性。显然,它将扩展Magento核心客户设置类,即Mage_Customer_Model_Entity_Setup。

步骤4 –使用以下代码在\ app \ code \ local \ Scommerce \ Customer \ Entity \ Setup.php中创建设置类

class Scommerce_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup
{
 
}

步骤5 –最后一步是使用以下代码在\ app \ code \ local \ Scommerce \ Customer \ sql \ scommercecustomer_setup / mysql4-install.0.0.1.php文件中创建属性

/**
 * Creating custom attributes
 */
 
/* @var $installer Scommerce_Customer_Model_Entity_Setup */
$installer = $this;
 
$installer->startSetup();
 
$installer->addAttribute('customer', 'new_field_name', array(
        'user_defined'    => 1,
    'label'       => 'New Field Label Name',
    'type'        => 'int',
    'input'       => 'text',
    'visible'     => false,
    'required'    => false,
    ));
 
$installer->endSetup();

就这样,就这么简单。希望本文对您有所帮助。请留下您的评论,让我们知道您的想法?谢谢。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论