Esempio n. 1
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     if (false === ($handle = fopen($fileName, "rb"))) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('Cannot open file: %s', $fileName));
         return false;
     }
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     if (false !== ($rowData = fgetcsv($handle, 1024, '|'))) {
         $skuColumn = array_search('ITEM_NUM', $rowData);
         $columns = array();
         foreach (self::$columns as $key => $value) {
             $columns[] = array_search($key, $rowData);
         }
     } else {
         return array();
     }
     $result = array();
     while (false !== ($rowData = fgetcsv($handle, 1024, '|'))) {
         $data = array($rowData[$skuColumn]);
         foreach ($columns as $columnPos) {
             $data[] = '+' == $rowData[$columnPos] ? 10 : (int) $rowData[$columnPos];
         }
         $result[] = $data;
     }
     return $result;
 }
Esempio n. 2
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     $result = array();
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     $fileHandle = fopen($fileName, 'r');
     $firstLine = true;
     while (false !== ($values = fgetcsv($fileHandle))) {
         if ($firstLine) {
             $this->_detectColumnPositions($values);
             $firstLine = false;
         }
         $items = array();
         foreach (self::$_columnPositions as $colIndex => $colPosition) {
             if (!$colIndex) {
                 $items[] = $values[$colPosition];
                 // SKU
             } else {
                 $items[] = '+' == $values[$colPosition] ? 10 : (int) $values[$colPosition];
             }
         }
         $result[] = $items;
     }
     fclose($fileHandle);
     return $result;
 }
Esempio n. 3
0
 public function parseFile($fileName, $inventoryType)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     $result = array();
     $data = file($fileName, FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES);
     $pattern = $inventoryType == 'master' ? self::$_itemMasterColumns : self::$_invlistColumns;
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     foreach ($data as $line) {
         $result[] = self::parseLineByPattern($pattern, $line);
     }
     return $result;
 }
Esempio n. 4
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     $result = array();
     $data = file($fileName, FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES);
     foreach ($data as $line) {
         $values = explode("\t", $line);
         if (count($values) < 2 || '' === $values[2]) {
             continue;
         }
         $result[$values[0]] = (int) $values[2];
     }
     return $result;
 }
Esempio n. 5
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     $result = array();
     $fileHandle = fopen($fileName, 'r');
     while (false !== ($values = fgetcsv($fileHandle))) {
         if (count($values) < 2) {
             continue;
         }
         //			$result[$values[0]] = array($values[4], $values[5]);
         $result[$values[0]] = $values[1];
     }
     fclose($fileHandle);
     return $result;
 }
Esempio n. 6
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     $result = array();
     $fileHandle = fopen($fileName, 'r');
     while (false !== ($values = fgetcsv($fileHandle, 0, '|'))) {
         if ($firstLine) {
             $this->_detectColumnPositions($values);
             $firstLine = false;
             continue;
         }
         $result[$values[self::$_columnPositions[0]]] = (int) $values[self::$_columnPositions[1]];
     }
     fclose($fileHandle);
     return $result;
 }
Esempio n. 7
0
 public function parseFile($fileName)
 {
     if (!file_exists($fileName)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('no such data file: %s', $fileName));
         return false;
     }
     Vikont_Pulliver_Helper_Data::type("Parsing {$fileName}...");
     $result = array();
     $fileHandle = fopen($fileName, 'r');
     while (false !== ($values = fgetcsv($fileHandle))) {
         //			$itemNumber = self::formatItemNumber($values[0], $values[1]);
         //			unset($values[0]);
         //			$result[$itemNumber] = $values;
         //			self::convertItemNumberToSKU($itemNumber)
         $result[self::formatItemNumber($values[0], $values[1])] = $values;
     }
     fclose($fileHandle);
     unset($result['Part Number']);
     return $result;
 }
Esempio n. 8
0
umask(0);
require_once $mageRoot . '/Vic.php';
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Vikont_Pulliver_Model_Log::setLogFileName('pulliver.log');
Vikont_Pulliver_Helper_Data::setSilentExceptions(false);
Vikont_Pulliver_Helper_Data::type("\nKawasaki Converter started...\n");
$commonHelper = Mage::helper('pulliver');
$moduleHelper = Mage::helper('pulliver/Kawasaki');
$skuHelper = Mage::helper('pulliver/Sku');
try {
    $params = isset($argv) ? Vikont_Pulliver_Helper_Data::getCommandLineParams($argv) : new Varien_Object($_GET);
    if ($downloadedFileName = $params->getData('file')) {
        Vikont_Pulliver_Helper_Data::type(sprintf('Using local file %s', $downloadedFileName));
    } else {
        //		$downloadedFileName = $moduleHelper->downloadFile();
        Vikont_Pulliver_Helper_Data::type('No file to convert');
        die;
    }
    $update = $moduleHelper->parseFile($downloadedFileName);
    $outputFileName = $moduleHelper->getLocalFileName($downloadedFileName);
    $fileHandle = $commonHelper->openFile($outputFileName);
    $lineCounter = 0;
    foreach ($update as $item) {
        if ($sku = $skuHelper->getSkuByItemNumber('KA', $itemNumber)) {
            fputcsv($fileHandle, array($sku, $item));
            $lineCounter++;
        }
    }
    fclose($fileHandle);
    Vikont_Pulliver_Helper_Data::inform(sprintf('Successfully created file %s, %d lines processed, %d lines added', $outputFileName, count($update), $lineCounter));
} catch (Exception $e) {
Esempio n. 9
0
Mage::app('admin')->setUseSessionInUrl(false);
umask(0);
require_once $mageRoot . '/Vic.php';
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Vikont_Pulliver_Model_Log::setLogFileName('pulliver.log');
Vikont_Pulliver_Helper_Data::setSilentExceptions(false);
Vikont_Pulliver_Helper_Data::type("\nKawasaki Converter started...\n");
$commonHelper = Mage::helper('pulliver');
$moduleHelper = Mage::helper('pulliver/Kawasaki');
try {
    $params = isset($argv) ? Vikont_Pulliver_Helper_Data::getCommandLineParams($argv) : new Varien_Object($_GET);
    $sourceFileName = $params->getData('file');
    if ($sourceFileName) {
        $sourceFileName = $commonHelper->getImportStorageLocation() . 'kawasaki/source/' . basename($sourceFileName);
        Vikont_Pulliver_Helper_Data::type(sprintf('Using local file %s', $sourceFileName));
    } else {
        Vikont_Pulliver_Helper_Data::type('Please specify a file to convert like ?file={path-to-file}');
        die;
    }
    $update = $moduleHelper->parseFile($sourceFileName);
    $outputFileName = $moduleHelper->getLocalFileName($sourceFileName);
    $fileHandle = $commonHelper->openFile($outputFileName);
    foreach ($update as $items) {
        fputcsv($fileHandle, $items);
    }
    fclose($fileHandle);
    Vikont_Pulliver_Helper_Data::inform(sprintf('Successfully created file %s having %d lines', $outputFileName, count($update)));
} catch (Exception $e) {
    Mage::logException($e);
    Vikont_Pulliver_Helper_Data::inform($e->getMessage());
}
Esempio n. 10
0
$commonHelper = Mage::helper('pulliver');
$moduleHelper = Mage::helper('pulliver/TroyLee');
$skuHelper = Mage::helper('pulliver/Sku');
try {
    $params = isset($argv) ? Vikont_Pulliver_Helper_Data::getCommandLineParams($argv) : new Varien_Object($_GET);
    if ($downloadedFileName = $params->getData('file')) {
        Vikont_Pulliver_Helper_Data::inform(sprintf('Skipped downloading, using local file %s', $downloadedFileName));
    } else {
        $downloadedFileName = $moduleHelper->downloadFile();
    }
    $update = $moduleHelper->parseFile($downloadedFileName);
    $outputFileName = $moduleHelper->getLocalFileName('inventory.csv');
    $fileHandle = $commonHelper->openFile($outputFileName);
    $lineCounter = 0;
    $outputMissingItems = $params->getData('missing_items');
    foreach ($update as $itemNumber => $item) {
        if ($sku = $skuHelper->getSkuByItemNumber('YL', $itemNumber)) {
            fputcsv($fileHandle, array($sku, $item));
            $lineCounter++;
        } else {
            if ($outputMissingItems) {
                Vikont_Pulliver_Helper_Data::type($itemNumber . ' ' . $item);
            }
        }
    }
    fclose($fileHandle);
    Vikont_Pulliver_Helper_Data::inform(sprintf('Successfully created file %s, %d lines processed, %d lines added', $outputFileName, count($update), $lineCounter));
} catch (Exception $e) {
    Mage::logException($e);
    Vikont_Pulliver_Helper_Data::inform($e->getMessage());
}