Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegansnyder/9096867 to your computer and use it in GitHub Desktop.
Save tegansnyder/9096867 to your computer and use it in GitHub Desktop.
Update telephone numbers to 00
<?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!';
@tegansnyder
Copy link
Author

upload to magento root and run by sshing in and typing:

php telephone-update.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment