Активный клиент не работает в Magento - PullRequest
3 голосов
/ 06 сентября 2011

Позвольте мне прояснить контекст:

Посмотрите на таблицу 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 |
+-----------+----------------+------------------+------------+----------------------+----------+--------------+----------+---------------------+---------------------+-----------+

У клиента есть идентификатор 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 ]

5 голосов
/ 06 сентября 2011

Меховой объект клиента, вам нужно создать статический атрибут с тем же именем, что и поле, которое вы создали.Например, ваш установщик 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 голосов
/ 09 июня 2016
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>, замените новую версию

очистить все кэши

Выйти из системы, затем войти

Перейти к управлению клиентами

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...