Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save magefast/80ce1cdc90360dece1af11e460e51416 to your computer and use it in GitHub Desktop.
Save magefast/80ce1cdc90360dece1af11e460e51416 to your computer and use it in GitHub Desktop.
Magento1: Telephone number for ordered SKU form List
<pre>
<h1>Telephone number for ordered SKU form List</h1>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('time_limit', 180);
set_time_limit(180);
$skuList = [];
$skuList['111'] = '111';
/**
* Magento
*/
require __DIR__ . '/app/Mage.php';
Mage::app();
$ordersCollection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*');
$ordersCollection->addAttributeToFilter('entity_id', array(
'from' => 534533,
'to' => null
));
$ordersProduct = array();
foreach ($ordersCollection as $o) {
$items = $o->getAllVisibleItems();
foreach ($items as $i) {
$itemData = $i->getData();
$sku = $itemData['sku'];
if (isset($skuList[$sku])) {
if (isset($itemData['product_id'])) {
$phone = $o->getBillingAddress()->getTelephone();
$phone = prepareTelephoneNumber($phone);
$ordersProduct[$itemData['sku']][$phone] = [$phone];
}
}
}
}
unset($ordersCollection);
$phoneList = [];
foreach ($ordersProduct as $key => $value) {
foreach ($value as $key2 => $value2) {
$phoneList[$key2] = $key2;
}
}
unset($ordersProduct);
foreach ($phoneList as $value) {
echo $value;
echo '<br>';
}
die('');
function prepareTelephoneNumber($value)
{
$value = preg_replace('/[^0-9]/', '', $value);
if (strlen($value) == 10) {
$value = '38' . $value;
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment