PHP MySQL – How to Mass Set Up a Custom Customer Attribute

MySQLPHP

Check this out:
enter image description here

I have two custom customer attributes: sms_promo and sms_on_order_change. Both have values only with 0 or 1.

My question is how for example i can set for all customers sms_promo to be 1 and sms_on_order_change to be 0 ?

Thanks in advance!

Best Answer

To set all custome attribuite value to all customer

Create new yourfile.php file in Magento Root Folder

<?php
    require_once realpath(dirname(__FILE__)) . '/app/Mage.php';
    Mage::app('');
    $customers = Mage::getModel('customer/customer')->getCollection();

    foreach($customers as $customer){
        $currentCustomer = Mage::getModel('customer/customer')->load($customer->getId());
        $currentCustomer->setSmsPromo(1);
        $currentCustomer->setSmsOnOrderChange(0);
        $currentCustomer->save();
    }
?>

Then run it on brower by load the following url www.domain.com/yourfile.php

Related Topic