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.

Revisions

  1. magefast renamed this gist Apr 24, 2023. 1 changed file with 0 additions and 0 deletions.
  2. magefast created this gist Apr 24, 2023.
    70 changes: 70 additions & 0 deletions Magento1: Telephone number for ordered SKU form List
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    <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;
    }