Magento 1.9 – Is It Safe to Change Website ID and Store ID Directly in customer_entity Table

customer-attributedatabasemagento-1.9

Is it safe to change Website ID and Store ID directly in table customer_entity? I can't change it in the backend on the customer information, because it's greyed out. The multistore setup is not using shared accounts across the websites, if thats the case.

Customer Account Details Example (Associate to Website disabled):

enter image description here

Thanks in advance,

Best Answer

As long as those customers hasn't placed any orders, I think it should be safer. Also I would suggest to update via Magento Customer Model instead of SQL.

You can find the sandbox script as below:

<?php

/**
 * @author      MagePsycho <info@magepsycho.com>
 * @website     http://www.magepsycho.com
 * @category    Export / Import
 */
require_once(dirname(__FILE__) . '/app/Mage.php');
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

// Prepare you customer update data
$customersData = array(
    1234 => array( // where 1234 is customerId
        'website_id' => 2,
        'store_id' => 6
    ),
    //...
);

$counter = 1;
foreach ($customersData as $customerId => $_customer) {
    if ($customer = Mage::getModel('customer/customer')->load($customerId)) {

        $websiteId = $_customer['website_id'];
        $storeId   = $_customer['store_id'];
        $customer->setWebsiteId($websiteId);
        $customer->setStoreId($storeId);
        $customer->save();
        echo sprintf("Customer (%d) with website(%d) and store(%d) successfully changed", $customerId, $websiteId, $storeId) . '<br />';

        $counter++;
    }
}
Related Topic