Last active
August 29, 2015 13:56
-
-
Save tegansnyder/9096867 to your computer and use it in GitHub Desktop.
Update telephone numbers to 00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('app/Mage.php'); | |
umask(0); | |
Mage::app(); | |
$db_conn = Mage::getSingleton('core/resource'); | |
$r_conn = $db_conn->getConnection('core_read'); | |
$w_conn = $db_conn->getConnection('core_write'); | |
$sql = <<<"SQL" | |
SELECT cv.value as `telephone`, e.* FROM customer_entity AS e | |
LEFT JOIN customer_address_entity_varchar AS cv | |
ON ( cv.attribute_id = ( | |
SELECT attribute_id FROM eav_attribute | |
WHERE attribute_code = 'telephone' | |
) | |
AND cv.entity_id = e.entity_id) | |
WHERE LENGTH(cv.value) <= 2 | |
SQL; | |
$results = $r_conn->fetchAll($sql); | |
$x = 0; | |
foreach ($results as $result) { | |
$update_sql = 'UPDATE customer_address_entity_varchar SET value = :new_value WHERE value_id = ' . $result['value_id']; | |
try { | |
$binds = array(); | |
$binds['new_value'] = '00'; | |
$w_conn->query($update_sql, $binds); | |
echo '#' . $x . ' success - value_id: ' . $result['value_id'] . PHP_EOL; | |
} catch (Exception $e) { | |
echo '#' . $x . ' error - value_id: ' . $result['value_id'] . PHP_EOL; | |
} | |
$x = $x + 1; | |
} | |
echo 'Done!'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
upload to magento root and run by sshing in and typing: