2011-09-06 41 views
3
工作

让我明确的背景:活跃客户没有在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 | [email protected] |  1 | 000000001 |  1 | 2007-08-30 23:23:13 | 2008-08-08 12:28:24 |   1 | 
|   2 |    1 |    0 |   1 | [email protected] |  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') 
+0

是您的请求从上到下执行并且您没有调用任何出口();死();或您的测试之间的类似?机会是你的交易没有执行。 –

+0

@Aton:我不这么认为,因为我没有使用'exit'或'die'功能。而属于'customer_eav_attribute'的其他属性可以正常更新。你能给我另一个解决方案吗?非常感谢。 – vietean

+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, 
)); 

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

+0

对不起@azakolyukin,我不太了解。你知道,'customer_entity'有'is_active'列。为什么我们需要做以上? – vietean

+0

@vietean他的意思是,如果你为DB创建自定义字段,你还必须为你的模型定制一个自定义属性,这样它才会知道该向db分贝什么 –

+0

@Anto S:真的,他的意思是如果在'customer_entity'中有一个属性,例如:email ...我们必须在表'customer_eav_attribute'&'eav_attribute'中创建一个''''定制属性'',就像'email'一样吗?那么,如果我们得到或更新“email属性”的值,那该怎么办? – vietean

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

步骤1)粘贴到应用程序/代码/核心/法师/客户/型号/资源此代码/ 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(); 

步骤3)转到这个路径:应用程序/代码/核心/法师/客户的/ etc/config.xml中,在上面标记<version>1.6.2.0.4</version>的代码,更换新的版本

刷新所有缓存

管理员注销,然后登录

转到管理客户

+0

请不要忘记将此新代码版本添加到此路径中的config.xml中:app/code/core/Mage/Customer/etc/config.xml在此标记中: – Majidiyan