Esempio n. 1
0
 /**
  * Post process input data
  *
  * @param array $inputData Prepared input data
  *
  * @return array
  */
 protected function postProcessInputData(array $inputData)
 {
     $config = $this->getConfiguration();
     if (!empty($inputData['packages'])) {
         foreach ($inputData['packages'] as $key => $package) {
             if (!$this->isDstCountryValid($package['country_code'])) {
                 $inputData = array();
                 $this->setError('There are no delivery to the country ' . $package['country_code']);
                 break;
             }
             $inputData['packages'][$key]['shipment_type'] = 'AU' === $package['country_code'] ? 'Domestic' : 'International';
             $inputData['packages'][$key]['package_type'] = $config->package_type;
             $inputData['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
             $inputData['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']);
             if (isset($inputData['packages'][$key]['box'])) {
                 $box = $inputData['packages'][$key]['box'];
                 $length = $box['length'];
                 $width = $box['width'];
                 $height = $box['height'];
             } else {
                 list($length, $width, $height) = $this->getPackageSize();
             }
             $inputData['packages'][$key]['length'] = $length;
             $inputData['packages'][$key]['width'] = $width;
             $inputData['packages'][$key]['height'] = $height;
         }
     } else {
         $this->setError('There are no defined packages to delivery');
     }
     return parent::postProcessInputData($inputData);
 }
Esempio n. 2
0
 /**
  * Post process input data
  *
  * @param array $inputData Prepared input data
  *
  * @return array
  */
 protected function postProcessInputData(array $inputData)
 {
     if (!empty($inputData['packages'])) {
         $inputData['total'] = 0;
         list($wUnit, ) = static::getWeightAndDimUnits($inputData['srcAddress']['country']);
         foreach ($inputData['packages'] as $key => $package) {
             $inputData['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'KGS' === $wUnit ? 'kg' : 'lbs');
             $inputData['packages'][$key]['weight'] = max(0.1, $inputData['packages'][$key]['weight']);
             $inputData['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']);
             $inputData['total'] += $inputData['packages'][$key]['subtotal'];
         }
     } else {
         $inputData = array();
     }
     return parent::postProcessInputData($inputData);
 }
Esempio n. 3
0
 /**
  * Post process input data
  *
  * @param array $inputData Prepared input data
  *
  * @return array
  */
 protected function postProcessInputData(array $inputData)
 {
     $result = array();
     if (!empty($inputData['packages']) && !empty($inputData['srcAddress']) && !empty($inputData['dstAddress'])) {
         $result = $inputData;
         $result['packages'] = array();
         foreach ($inputData['packages'] as $packKey => $package) {
             $package['price'] = sprintf('%.2f', $package['subtotal']);
             // decimal, min=0.00, totalDigits=10
             $package['weight'] = round(\XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'lbs'), 4);
             $result['packages'][] = $package;
         }
     }
     return parent::postProcessInputData($result);
 }
Esempio n. 4
0
 /**
  * Post process input data
  *
  * @param array $inputData Prepared input data
  *
  * @return array
  */
 protected function postProcessInputData(array $inputData)
 {
     $commonData = isset($inputData['commonData']) ? $inputData['commonData'] : array();
     unset($inputData['commonData']);
     if (!empty($inputData['packages'])) {
         foreach ($inputData['packages'] as $key => $package) {
             $package = array_merge($package, $commonData);
             $package['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg');
             \XLite\Module\XC\CanadaPost\Core\API::setCanadaPostConfig($this->getConfiguration());
             $package['subtotal'] = \XLite\Module\XC\CanadaPost\Core\API::applyConversionRate($package['subtotal']);
             $inputData['packages'][$key] = $package;
         }
     } else {
         $inputData = array();
     }
     return parent::postProcessInputData($inputData);
 }