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; }
public function getZip() { $dealerCode = 'TEM026'; $userName = '******'; $password = '******'; $loginUrl = 'https://www.lemansnet.com/login'; $pricingUrl = 'https://www.lemansnet.com/pricing/2013/pos'; //Log In and Retrieve Token $myToken = $this->lemans_retrieve_token($dealerCode, $userName, $password, $loginUrl); if (!empty($myToken)) { //Body Contents for Retrieving Zip File $zipRequestBody = <<<ZIPREQUESTBODY <pricing> \t<whoForDealer> \t\t<dealerCode>{$dealerCode}</dealerCode> \t</whoForDealer> \t<rememberPreferences>1</rememberPreferences> </pricing> ZIPREQUESTBODY; //Make Request for Zip File return $this->lemans_request_pricing_files($pricingUrl, $zipRequestBody, $myToken, 'text/xml'); } else { Vikont_Pulliver_Helper_Data::inform('User validation has failed and a request could not be made'); return false; exit; } }
public static function isCLIMode() { if (null === self::$_CLIMode) { self::$_CLIMode = php_sapi_name() == 'cli'; } return self::$_CLIMode; }
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; }
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; }
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; }
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; }
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; }
public function decodeFile($fileName) { if (!file_exists($fileName)) { Vikont_Pulliver_Helper_Data::throwException(sprintf('No such data file: %s', $fileName)); return false; } $jsonData = file_get_contents($fileName); return $this->decodeJson($jsonData); }
umask(0); // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Vikont_Pulliver_Model_Log::setLogFileName('pulliver.log'); Vikont_Pulliver_Helper_Data::setSilentExceptions(false); Vikont_Pulliver_Helper_Data::inform("\nMotonation Connector started...\n"); $commonHelper = Mage::helper('pulliver'); $moduleHelper = Mage::helper('pulliver/Motonation'); $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; foreach ($update as $itemNumber => $qty) { if ($sku = $skuHelper->getSkuByItemNumber('MT', $itemNumber)) { fputcsv($fileHandle, array($sku, $qty)); $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) { Mage::logException($e); Vikont_Pulliver_Helper_Data::inform($e->getMessage()); }
<?php ini_set('memory_limit', '2048M'); ini_set('max_execution_time', '600'); set_time_limit(0); $mageRoot = dirname(dirname(getcwd())); require $mageRoot . '/Vic.php'; require $mageRoot . '/app/Mage.php'; Mage::app('admin')->setUseSessionInUrl(false); umask(0); // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Vikont_Pulliver_Model_Log::setLogFileName('pulliver.log'); Vikont_Pulliver_Helper_Data::setSilentExceptions(true); $commonHelper = Mage::helper('pulliver'); $moduleHelper = Mage::helper('pulliver/LightSpeed'); $skuHelper = Mage::helper('pulliver/Sku'); //vd(Vikont_Pulliver_Helper_Sku::getSkuByItemNumber('punlim', '4010-0075')); vd(Vikont_Pulliver_Helper_Sku::getSkuByItemNumber('FX', '01179-001-S'));
protected function lemans_retrieve_token($dealerCode, $userName, $password, $loginURL) { $requestItems = array('rememberMe' => 'on', 'dealerCode' => $dealerCode, 'dm' => 4, 'userName' => $userName, 'password' => $password); $requestString = $this->lemans_generate_query_parameter_string($requestItems); $tokenRequest = $this->lemans_do_token_request($loginURL . $requestString, null); if (!$tokenRequest) { Vikont_Pulliver_Helper_Data::throwException('PU: Login Unsuccessful'); } else { return $tokenRequest; } }