/** * Call "Create Authorized Return" request by the ProductsReturn model * * @param \XLite\Module\XC\CanadaPost\Model\ProductsReturn $return Canada Post return model * * @return \XLite\Core\CommonCell */ public function callCreateAuthorizedReturnByProductsReturn(\XLite\Module\XC\CanadaPost\Model\ProductsReturn $return) { $xmlHeader = '<' . '?xml version="1.0" encoding="utf-8"?' . '>'; // Convert weight into KG $itemsWeight = \XLite\Core\Converter::convertWeightUnits($return->getItemsTotalWeight(), \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg'); $itemsWeight = static::adjustFloatValue($itemsWeight, 3, 0.1, 999.999); $requestData = <<<XML {$xmlHeader} <authorized-return xmlns="http://www.canadapost.ca/ws/authreturn-v2"> <service-code>{$return->getOrder()->getCapostShippingMethodCode()}</service-code> {$this->getXmlBlockReturnerAddress($return->getOrder()->getProfile())} {$this->getXmlBlockReceiverAddress()} <parcel-characteristics> <weight>{$itemsWeight}</weight> </parcel-characteristics> <print-preferences> <output-format>8.5x11</output-format> <encoding>PDF</encoding> </print-preferences> <settlement-info></settlement-info> </authorized-return> XML; return $this->callCreateAuthorizedReturn($requestData); }
/** * prepareInputData * * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier * * @return void */ protected function prepareInputData(\XLite\Logic\Order\Modifier\Shipping $modifier) { $result = null; // Fill $result array by data from the order if ('AU' == \XLite\Core\Config::getInstance()->Company->location_country) { $result['srcAddress']['zipcode'] = \XLite\Core\Config::getInstance()->Company->location_zipcode; $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier); if (isset($address)) { $result['dstAddress'] = $address; $result['weight'] = \XLite\Core\Converter::convertWeightUnits($modifier->getWeight(), \XLite\Core\Config::getInstance()->General->weight_unit, 'g'); } else { $result = null; } } return $result; }
/** * Get single item weight in KG * * @param boolean $adjustFloatValue Flag - adjust float value or not (OPTIONAL) * * @return float */ public function getWeightInKg($adjustFloatValue = false) { // Convert weight from store units to KG (weight must be in KG) $weight = \XLite\Core\Converter::convertWeightUnits($this->getWeight(), \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg'); if ($adjustFloatValue) { // Adjust according to the XML element schema $weight = \XLite\Module\XC\CanadaPost\Core\Service\AService::adjustFloatValue($weight, 3, 0, 99.999); } return $weight; }
/** * Get package limits * * @return array */ protected function getPackageLimits() { $limits = parent::getPackageLimits(); $config = $this->getConfiguration(); // Weight in store weight units $limits['weight'] = \XLite\Core\Converter::convertWeightUnits($config->max_weight, 'kg', \XLite\Core\Config::getInstance()->Units->weight_unit); list($limits['length'], $limits['width'], $limits['height']) = $this->getPackageSize(); return $limits; }
/** * Returns array(pounds, ounces) from a weight value in specific weight units * * @param float $weight Weight value * * @return array */ public function getPoundsOunces($weight) { $pounds = $ounces = 0; switch (\XLite\Core\Config::getInstance()->Units->weight_unit) { case 'lbs': $pounds = $weight; break; case 'oz': $ounces = $weight; break; default: $ounces = \XLite\Core\Converter::convertWeightUnits($weight, \XLite\Core\Config::getInstance()->Units->weight_unit, 'oz'); } if (intval($pounds) < $pounds) { $ounces = ($pounds - intval($pounds)) * 16; $pounds = intval($pounds); } return array($pounds, round($ounces, 1)); }
/** * Returns array of data for request * * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Array of input data or a shipping order modifier * * @return array */ protected function prepareInputData($inputData) { $data = array(); $commonData = array(); if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) { if ('CA' == \XLite\Core\Config::getInstance()->Company->location_country) { $commonData['srcAddress'] = array('zipcode' => \XLite\Core\Config::getInstance()->Company->location_zipcode); } $commonData['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData); if (!empty($commonData['srcAddress']) && !empty($commonData['dstAddress'])) { $data['packages'] = $this->getPackages($inputData); } } else { $data = $inputData; } if (!empty($data['packages'])) { foreach ($data['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'); $package['subtotal'] = \XLite\Module\XC\CanadaPost\Core\API::applyConversionRate($package['subtotal']); $data['packages'][$key] = $package; } } else { $data = array(); } return $data; }
/** * prepareInputData * * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier (from order) or array of input data (from test controller) * * @return void */ protected function prepareInputData($inputData) { $data = array(); if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) { $data = $this->prepareDataFromModifier($inputData); } else { $data = $inputData; } if (!empty($data['packages'])) { $data['total'] = 0; list($wUnit, $dUnit) = static::getWeightAndDimUnits($data['srcAddress']['country']); foreach ($data['packages'] as $key => $package) { $data['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'KGS' == $wUnit ? 'kg' : 'lbs'); $data['packages'][$key]['weight'] = max(0.1, $data['packages'][$key]['weight']); $data['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']); $data['total'] += $data['packages'][$key]['subtotal']; } } else { $data = array(); $this->errorMsg = 'There are no defined packages to delivery'; } return $this->getQuoted($data); }
/** * Returns array of data for request * * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Array of input data or a shipping order modifier * * @return array */ protected function prepareRequestData($inputData) { $result = array(); $data = array(); $data['packages'] = array(); if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) { $data['srcAddress'] = array('zipcode' => \XLite\Core\Config::getInstance()->Company->location_zipcode, 'country' => \XLite\Core\Config::getInstance()->Company->location_country); if (isset(\XLite\Core\Config::getInstance()->Company->location_state)) { $data['srcAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById(\XLite\Core\Config::getInstance()->Company->location_state); } $data['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData); if (empty($data['dstAddress']['country'])) { $data['dstAddress'] = null; } elseif (isset($data['dstAddress']['state'])) { $data['dstAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById($data['dstAddress']['state']); } $data['packages'] = $this->getPackages($inputData); // Detect if COD payment method has been selected by customer on checkout if ($inputData->getOrder()->getFirstOpenPaymentTransaction()) { $paymentMethod = $inputData->getOrder()->getPaymentMethod(); if ($paymentMethod && 'COD_FEDEX' == $paymentMethod->getServiceName()) { $data['cod_enabled'] = true; } } } else { $data = $inputData; } if (!empty($data['packages']) && !empty($data['srcAddress']) && !empty($data['dstAddress'])) { $result = $data; $result['packages'] = array(); foreach ($data['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 $result; }
/** * prepareInputData * * @param array|\XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier (from order) or * array of input data (from test controller) * * @return array */ protected function prepareInputData($inputData) { if ($inputData instanceof \XLite\Logic\Order\Modifier\Shipping) { $data = $this->prepareDataFromModifier($inputData); } else { $data = $inputData; } if (!empty($data['packages'])) { foreach ($data['packages'] as $key => $package) { if (!$this->isDstCountryValid($package['country_code'])) { $data = array(); $this->errorMsg = 'There are no delivery to the country ' . $package['country_code']; break; } $data['packages'][$key]['shipment_type'] = 'AU' == $package['country_code'] ? 'Domestic' : 'International'; $data['packages'][$key]['package_type'] = \XLite\Core\Config::getInstance()->CDev->AustraliaPost->package_type; $data['packages'][$key]['weight'] = \XLite\Core\Converter::convertWeightUnits($package['weight'], \XLite\Core\Config::getInstance()->Units->weight_unit, 'kg'); $data['packages'][$key]['subtotal'] = $this->getPackagesSubtotal($package['subtotal']); if (isset($data['packages'][$key]['box'])) { $length = $data['packages'][$key]['box']['length']; $width = $data['packages'][$key]['box']['width']; $height = $data['packages'][$key]['box']['height']; } else { list($length, $width, $height) = $this->getAuspostPackageSizes(); } $data['packages'][$key]['length'] = $length; $data['packages'][$key]['width'] = $width; $data['packages'][$key]['height'] = $height; } } else { $this->errorMsg = 'There are no defined packages to delivery'; } return $data; }
/** * 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); }