0

I created a new customer attribute (Drop Down) and added it to the registration form.

Attribute details found in eav_attribute table:

enter image description here

Everything work as expected, attribute is added to the customer when new account is registered or an existing account was edited and the attribute was added. I can find that in the table customer_entity_int:

enter image description here

Now, I have about 90,000 customers and I need to set a value of this attribute.

How can I update all the customers custom drop down attribute with the above value? Any method would suit me, PHP or SQL.

4
  • You can use Collection to set attribute value for all customers.
    – Sourav
    Commented Nov 27, 2018 at 4:11
  • @Sourav thank for tips :) any more advice how to do so? Tutorials or further information? Still struggling... :/
    – Greg
    Commented Nov 27, 2018 at 9:10
  • which M2 version you are using ? Commented Nov 29, 2018 at 6:42
  • I am using Magento ver. 2.2.6
    – Greg
    Commented Nov 29, 2018 at 16:15

2 Answers 2

1
+50

Here is the quick and dirty sql solution:
You need to run this:

INSERT IGNORE INTO customer_entity_int (attribute_id, entity_id, value) 
SELECT 'attribute_id_here' as attribute_id, entity_id, 'default_value' as value from customer_entity;

So let's say you have the attribute id 529 for your new attribute and you want to set the value 1370 for all customers for this attribute, jut run:

INSERT IGNORE INTO customer_entity_int (attribute_id, entity_id, value) 
SELECT 529 as attribute_id, entity_id, 1370 as value from customer_entity;
2
  • Thanks for reply. I leave the question open for further solutions (if any).
    – Greg
    Commented Nov 29, 2018 at 16:16
  • If you want a clean versiin you can put this in an upgrade data script
    – Marius
    Commented Nov 29, 2018 at 17:12
0

you can create upgrade Data script and set/change following value in your custom attribute array in your module . 'default' => '0',

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.