活跃的客户无法在Magento中工作

时间:2011-09-06 07:51:46

标签: magento

让我说清楚背景:

查看customer_entity表:

+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+---------------------+---------------------+-----------+
| entity_id | entity_type_id | attribute_set_id | website_id | email                | group_id | increment_id | store_id | created_at          | updated_at          | is_active |
+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+---------------------+---------------------+-----------+
|         1 |              1 |                0 |          1 | john.doe@example.com |        1 | 000000001    |        1 | 2007-08-30 23:23:13 | 2008-08-08 12:28:24 |         1 |
|         2 |              1 |                0 |          1 | vietean@gmail.com    |        1 |              |        1 | 2011-08-15 09:51:20 | 2011-09-06 07:31:17 |         0 |
+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+---------------------+---------------------+-----------+

客户的ID为2,is_active属性为0,现在我想更改为1.

$customerId = 2;
$modelCustomer = Mage::getModel('customer/customer')->load($customerId);
$modelCustomer->setIsActive(1);
$modelCustomer->save();

但是,它不起作用。 我该如何解决它或者我错过了什么?

更新

我可以得到这个客户的积极性。

$modelCustomer->getIsActive();//0

调试:

当我显示日志时,我刚看到,我猜它没有更新is_active属性:

UPDATE `customer_entity` SET `entity_id` = ?, `entity_type_id` = ?, `attribute_set_id` = ?, `website_id` = ?, `email` = ?, `group_id` = ?, `increment_id` = ?, `store_id` = ?, `created_at` = ?, `updated_at` = ? WHERE (entity_id='2')

2 个答案:

答案 0 :(得分:5)

您需要创建与您创建的字段同名的静态属性的客户实体。例如,您的sql安装程序可能是这样的:

$installer->getConnection()->addColumn($installer->getTable('customer_entity'), 'is_active', "TINYINT(2)");

$installer->addAttribute('customer', 'is_active', array(
'label'         => 'Active',
'type'          => 'static',
'visible'       => 1,
'required'      => 0,
'position'      => 1,
));

如果您需要解释,可以调试保存过程。

答案 1 :(得分:0)

In order to show and use **is_active** field of the table **customer_entity**

步骤1)将此代码粘贴到app / code / core / Mage / Customer / Model / Resource / Setup.php

 'is_active' => array(
                        'label'         => 'MyActive',
                        'type'          => 'static',
                        'input'         => 'text',
                        'visible'       => true,
                        'required'      => false,
                        'position'      => 65,
                    ),

step 2) run this query in phpmyadmin
select * from core_resource;
find the version of customer_setup
for example if in your store this is 1.6.2.0.5 so make a file by this name:
upgrade-1.6.2.0.5-1.6.2.0.6.php
this means from version 1.6.2.0.5 will be upgrade to 1.6.2.0.6
copy this file in this path:
app/code/core/Mage/Customer/sql/customer_setup/

copy this code in it:
$installer = $this;

$middlenameAttributeCode = 'is_active';

$installer->addAttribute('customer', $middlenameAttributeCode, array(
    'type'       => 'static',
    'label'      => 'MyActive',
    'input'      => 'text',
    'required'   => 0,
    'sort_order' => 50,
    'is_visible' => 1,
    'visible'       => 1,
    'position'   => 65,
));

$middlenameAttribute = Mage::getSingleton('eav/config')
    ->getAttribute('customer', $middlenameAttributeCode);
$middlenameAttribute->setData('used_in_forms', array(
    'customer_account_create',
    'customer_account_edit',
    'checkout_register',
    'adminhtml_customer',
    'adminhtml_checkout'
));
$middlenameAttribute->save();

step3)转到此路径:app / code / core / Mage / Customer / etc / config.xml,在标记<version>1.6.2.0.4</version>的代码上方,替换新版本

刷新所有缓存

admin logout然后登录

转到管理客户