开发者

Active a customer doesn't work in Magento

Let me make clear the context:

Look at the customer_entity table:

+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+----------开发者_Go百科-----------+---------------------+-----------+
| 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 |
+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+---------------------+---------------------+-----------+

At the customer has id is 2 and is_active attribute is 0, now I want to change to 1.

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

But, it doesn't work. How can I fix it or I am missing something?

Update:

I can getIsActive of this customer.

$modelCustomer->getIsActive();//0

Debugging:

When I showed log, I just saw, I guessed it did not update is_active attribute:

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')


Fur customer entity you need to create static attribute with the same name as field you created. For example, your sql installer can be something like this:

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

If you need explanation of this you can debug saving process.


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

step 1) paste this code in 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) goto this path: app/code/core/Mage/Customer/etc/config.xml , in above of the code in tag <version>1.6.2.0.4</version>, replace your new version

flush all caches

admin logout then login

goto manage customers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜