Exemplo n.º 1
0
 public function generateDropFile($data, $sMethods = null)
 {
     if (isset($data['response'])) {
         $data = $data['response'][0];
     }
     $state = $data['parties']['delivery']['addressLine4'];
     $countryCode = $data['parties']['delivery']['countryIsoCode'];
     $stateAbbrev = null;
     $isResidential = null;
     $shippingMethod = '';
     if ($data['parties']['delivery']['companyName'] === '') {
         XLibOutput::pl('Is residential delivery address');
         $isResidential = true;
     } else {
         XLibOutput::pl('Not residential delivery address');
         $isResidential = false;
     }
     if (strlen($state) > 2) {
         if ($countryCode == 'US') {
             $stateAbbrev = \XLib\States::usStateToAbbrev($state);
         } else {
             $stateAbbrev = \XLib\States::canadaStateToAbbrev($state);
         }
     } else {
         $stateAbbrev = $state;
     }
     // get shipping method
     if ($sMethods !== null) {
         $sMethodId = intval($data['delivery']['shippingMethodId']);
         $sMethod = '';
         foreach ($sMethods as $key => $value) {
             if (intval($value['id']) === $sMethodId) {
                 $sMethod = $value['name'];
             }
         }
         XLibOutput::pl('Shipping method: ' . $sMethod);
     } else {
         $sMethod = '';
     }
     // MDE S
     $result_s = array($data['id'], '', $data['parties']['delivery']['addressFullName'], $data['parties']['delivery']['addressLine1'], $data['parties']['delivery']['addressLine2'], $data['parties']['delivery']['addressLine3'], $stateAbbrev, $data['parties']['delivery']['postalCode'], '', '', '', '', '', '', '', 'P', '', '', '', '', '', '', '', $isResidential == true ? 'Y' : 'N', '', '', $sMethod, '', '', '', '', '', '', '', '', '', '');
     // MDE P
     $orderRows = $data['orderRows'];
     $output = '';
     foreach ($orderRows as $key => $value) {
         $id = $key;
         $item = $value;
         if (isset($item['productSku'])) {
             $result_p = array($data['id'], '', $item['productSku'], '', '', '', '', '', '', '', '', '', '', intval($item['quantity']['magnitude']), '', '', '', '', '', '', '', '', '', '', '', '');
             $str = join(',', $result_p);
             $output .= $str . "\n";
         }
     }
     $file_s = 'MDE' . substr($data['id'], strlen($data['id']) - 4) . 'S' . '.' . strval(date('z') + 1);
     file_put_contents($file_s, join(',', $result_s));
     $file_p = 'MDE' . substr($data['id'], strlen($data['id']) - 4) . 'P' . '.' . strval(date('z') + 1);
     file_put_contents($file_p, join(',', $result_p));
     return array('S' => $file_s, 'P' => $file_p);
 }
Exemplo n.º 2
0
 public function sendDropFile($dropFile)
 {
     $host = '127.0.0.1';
     $user = '******';
     $pass = '******';
     $todir = 'ftp_testing/janssen';
     $ftp = new \XLib\FTP($host, $user, $pass);
     $ftp->connect() or die('Failed to connect to FTP');
     $ftp->login() or die('Failed to login to FTP');
     $ftp->changeDirectory($todir);
     if (!$ftp->fileExists($dropFile)) {
         XLibOutput::pl('Sending files to remote server via FTP');
         $ftp->putFile($dropFile, $dropFile) or die('Failed to transfer file');
         XLibOutput::pl('Finished sending file to remote server.');
     } else {
         XLibOutput::pl('Files not sent. Already exists on remote FTP server.');
     }
     $ftp->close();
     if (file_exists($dropFile)) {
         @unlink($dropFile);
     }
     return $this;
 }