Update Customer name and surname and customer address name and surname

<pre lang="sql">
-- Firstname --
 
SELECT * FROM  customer_entity_varchar c2
INNER JOIN customer_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 1 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='firstname' AND entity_type_id=1)
INNER JOIN mytable m1 ON m1.magento_id = c2.entity_id AND firstname='First name' AND lastname='Last name' AND migrated=1
AND c2.VALUE='First Name';
 
 
UPDATE customer_entity_varchar c2
INNER JOIN customer_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 1 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='firstname' AND entity_type_id=1)
INNER JOIN mytable m1 ON m1.magento_id = c2.entity_id AND firstname='First name' AND lastname='Last name' AND migrated=1
AND c2.VALUE='First Name'
SET c2.VALUE=m1.shipping_firstname;
 
SELECT * FROM  customer_address_entity_varchar c2
INNER JOIN customer_address_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 2 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='firstname' AND entity_type_id=2)
INNER JOIN mytable m1 ON m1.magento_id = c1.parent_id AND m1.firstname='First name' AND m1.lastname='Last name' AND migrated=1
AND c2.VALUE='First Name';
 
 
UPDATE customer_address_entity_varchar c2
INNER JOIN customer_address_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 2 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='firstname' AND entity_type_id=2)
INNER JOIN mytable m1 ON m1.magento_id = c1.parent_id AND m1.firstname='First name' AND m1.lastname='Last name' AND migrated=1
AND c2.VALUE='First Name'
SET c2.VALUE=m1.shipping_firstname;
 
-- Lastname --
 
SELECT * FROM  customer_entity_varchar c2
INNER JOIN customer_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 1 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='lastname' AND entity_type_id=1)
INNER JOIN mytable m1 ON m1.magento_id = c2.entity_id AND firstname='First name' AND lastname='Last name' AND migrated=1
AND c2.VALUE='Last Name';
 
 
UPDATE customer_entity_varchar c2
INNER JOIN customer_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 1 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='lastname' AND entity_type_id=1)
INNER JOIN mytable m1 ON m1.magento_id = c2.entity_id AND firstname='First name' AND lastname='Last name' AND migrated=1
AND c2.VALUE='Last Name'
SET c2.VALUE=m1.shipping_lastname;
 
 
SELECT * FROM  customer_address_entity_varchar c2
INNER JOIN customer_address_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 2 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='lastname' AND entity_type_id=2)
INNER JOIN mytable m1 ON m1.magento_id = c1.parent_id AND m1.firstname='First name' AND m1.lastname='Last name' AND migrated=1
AND c2.VALUE='Last Name';
 
 
UPDATE customer_address_entity_varchar c2
INNER JOIN customer_address_entity c1 ON c1.entity_id = c2.entity_id AND c2.entity_type_id = 2 AND c2.attribute_id = 
(SELECT attribute_id FROM eav_attribute WHERE attribute_code='lastname' AND entity_type_id=2)
INNER JOIN mytable m1 ON m1.magento_id = c1.parent_id AND m1.firstname='First name' AND m1.lastname='Last name' AND migrated=1
AND c2.VALUE='Last Name'
SET c2.VALUE=m1.shipping_lastname;

Leave a Reply