Beispiel #1
0
 /**
  * Postprocess mapped data
  * 
  * @return array
  */
 protected function getPurchaserBillingAddress()
 {
     $modifierModel = $this->inputData->getOrder()->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING');
     $modifierLogicModel = $modifierModel->getModifier();
     $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifierLogicModel);
     return $this->getShippingAdressByDstAddressArray($dstAddress);
 }
Beispiel #2
0
 protected function getPhone()
 {
     $modifier = $this->getOrder()->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING')->getModifier();
     $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier);
     $addressObject = $this->getOrder()->getProfile()->getShippingAddress();
     $phone = $addressObject && $addressObject->getPhone() ? $addressObject->getPhone() : '';
     return $phone;
 }
Beispiel #3
0
 /**
  * Register new shipping processor. All processors classes must be
  * derived from \XLite\Model\Shipping\Processor\AProcessor class
  *
  * @param string $processorClass Processor class
  *
  * @return void
  */
 public static function registerProcessor($processorClass)
 {
     if (!isset(self::$registeredProcessors[$processorClass])) {
         if (\XLite\Core\Operator::isClassExists($processorClass)) {
             self::$registeredProcessors[$processorClass] = new $processorClass();
             uasort(self::$registeredProcessors, array(\XLite\Model\Shipping::getInstance(), 'compareProcessors'));
         }
     }
 }
Beispiel #4
0
 /**
  * Get total cost for base rate
  * 
  * @param mixed $quote Single quote line
  * 
  * @return float
  */
 protected function getBaseRate($quote)
 {
     $baseRate = $quote->total->value;
     if ($this->getAdditionalData('requested') && $this->getAdditionalData('requested') instanceof \XLite\Logic\Order\Modifier\Shipping) {
         $order = $this->getAdditionalData('requested')->getOrder();
         $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($this->getAdditionalData('requested'));
         $baseRate = Processor\PitneyBowes::getFullTransportationCost($order->getSubtotal(), $address['country'], $quote);
     }
     return $baseRate;
 }
Beispiel #5
0
 /**
  * Returns shipping markups for order modifier by specified processor
  *
  * @param string                               $processor Processor class name
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier  Shipping order modifier
  *
  * @return array
  */
 public function findMarkupsByProcessor($processor, \XLite\Logic\Order\Modifier\Shipping $modifier)
 {
     $result = array();
     $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier);
     $customerZones = array();
     if (null !== $address) {
         // Get customer zone sorted out by weight
         $customerZones = \XLite\Core\Database::getRepo('XLite\\Model\\Zone')->findApplicableZones($address);
     }
     // Iterate through zones and generate markups list
     foreach ($customerZones as $zone) {
         $markups = $this->defineFindMarkupsByProcessorQuery($processor, $modifier, $zone->getZoneId())->getResult();
         foreach ($markups as $markupData) {
             $markup = $markupData[0];
             if ($markup->getShippingMethod() && !isset($result[$markup->getShippingMethod()->getMethodId()])) {
                 $markup->setMarkupValue($markupData['markup_value']);
                 $result[$markup->getShippingMethod()->getMethodId()] = $markup;
             }
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Perform some actions at startup
  *
  * @return string
  */
 public static function init()
 {
     parent::init();
     // Register FedEx shipping processor
     \XLite\Model\Shipping::getInstance()->registerProcessor('XLite\\Module\\CDev\\FedEx\\Model\\Shipping\\Processor\\FEDEX');
 }
Beispiel #7
0
 /**
  * Perform some actions at startup
  *
  * @return string
  */
 public static function init()
 {
     parent::init();
     // Register USPS shipping processor
     \XLite\Model\Shipping::getInstance()->registerProcessor('\\XLite\\Module\\CDev\\USPS\\Model\\Shipping\\Processor\\USPS');
 }
Beispiel #8
0
 /**
  * Get processor class object
  *
  * @return \XLite\Model\Shipping\Processor\AProcessor
  */
 public function getProcessorObject()
 {
     $result = null;
     // Current processor ID
     $processor = $this->getProcessor();
     // List of all registered processors
     $processors = \XLite\Model\Shipping::getInstance()->getProcessors();
     // Search for processor object
     if ($processors) {
         foreach ($processors as $obj) {
             if ($obj->getProcessorId() == $processor) {
                 $result = $obj;
                 break;
             }
         }
     }
     return $result;
 }
Beispiel #9
0
 /**
  * Prepare input data from order shipping modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier($modifier)
 {
     $data = array();
     $data['srcAddress'] = array('city' => \XLite\Core\Config::getInstance()->Company->location_city, '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($modifier);
     if (isset($data['dstAddress']['state'])) {
         $data['dstAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById($data['dstAddress']['state']);
     }
     $data['packages'] = $this->getPackages($modifier);
     $data['cod_enabled'] = false;
     // Detect if COD payment method has been selected by customer on checkout
     if ($modifier->getOrder()->getFirstOpenPaymentTransaction()) {
         $paymentMethod = $modifier->getOrder()->getPaymentMethod();
         if ($paymentMethod && 'COD_UPS' == $paymentMethod->getServiceName()) {
             $data['cod_enabled'] = true;
         }
     }
     return $data;
 }
Beispiel #10
0
 /**
  * testGetDestinationAddress
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testGetDestinationAddress()
 {
     $order = $this->getTestOrder(true);
     $m = $order->getModifier('shipping', 'SHIPPING')->getModifier();
     $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($m);
     $this->assertTrue(is_array($address), 'getDestinationAddress() must return an array');
     $this->assertArrayHasKey('address', $address, 'Address must contain "address" key');
     $this->assertArrayHasKey('city', $address, 'Address must contain "city" key');
     $this->assertArrayHasKey('country', $address, 'Address must contain "country" key');
     $this->assertArrayHasKey('state', $address, 'Address must contain "state" key');
     $this->assertArrayHasKey('zipcode', $address, 'Address must contain "zipcode" key');
     $order = $this->getTestOrder(false);
     $m = $order->getModifier('shipping', 'SHIPPING')->getModifier();
     $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($m);
     $this->assertTrue(is_array($address), 'getDestinationAddress() must return an array');
     $this->assertArrayHasKey('address', $address, 'Address must contain "address" key');
     $this->assertArrayHasKey('city', $address, 'Address must contain "city" key');
     $this->assertArrayHasKey('country', $address, 'Address must contain "country" key');
     $this->assertArrayHasKey('state', $address, 'Address must contain "state" key');
     $this->assertArrayHasKey('zipcode', $address, 'Address must contain "zipcode" key');
     $this->assertEquals(\XLite\Base::getInstance()->config->Shipping->anonymous_country, $address['country'], 'Country does not match');
     $this->assertEquals(\XLite\Base::getInstance()->config->Shipping->anonymous_state, $address['state'], 'state does not match');
     $this->assertEquals(\XLite\Base::getInstance()->config->Shipping->anonymous_zipcode, $address['zipcode'], 'zipcode does not match');
     $this->assertEquals(\XLite\Base::getInstance()->config->Shipping->anonymous_city, $address['city'], 'city does not match');
     $this->assertEquals(\XLite\Base::getInstance()->config->Shipping->anonymous_address, $address['address'], 'address does not match');
 }
Beispiel #11
0
 /**
  * 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;
 }
Beispiel #12
0
 /**
  * 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;
 }
Beispiel #13
0
 /**
  * Perform some actions at startup
  *
  * @return string
  */
 public static function init()
 {
     parent::init();
     \XLite\Model\Shipping::getInstance()->registerProcessor('\\XLite\\Module\\XC\\AuctionInc\\Model\\Shipping\\Processor\\AuctionInc');
 }
Beispiel #14
0
 /**
  * 
  */
 public static function getProcessorObjectByProcessorId($processorId)
 {
     $result = null;
     $processors = \XLite\Model\Shipping::getInstance()->getProcessors();
     foreach ($processors as $obj) {
         if ($obj->getProcessorId() === $processorId) {
             $result = $obj;
             break;
         }
     }
     return $result;
 }
 /**
  * Retrieve shipping adress from modifier
  * 
  * @return array
  */
 protected function getShippingAdress()
 {
     $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($this->inputData);
     return $this->getShippingAdressByDstAddressArray($dstAddress);
 }
Beispiel #16
0
 /**
  * Get shipping estimate address
  *
  * @return string
  */
 protected function getEstimateAddress()
 {
     $string = '';
     $address = \XLite\Model\Shipping::getInstance()->getDestinationAddress($this->getModifier()->getModifier());
     if (is_array($address)) {
         $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find($address['country']);
         if ($address['state']) {
             $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($address['state']);
         } elseif ($this->getCart()->getProfile() && $this->getCart()->getProfile()->getShippingAddress()) {
             $state = $this->getCart()->getProfile()->getShippingAddress()->getState();
         }
     }
     if (isset($country)) {
         $string = $country->getCountry();
     }
     if ($state) {
         $string .= ', ' . ($state->getCode() ?: $state->getState());
     }
     $string .= ', ' . $address['zipcode'];
     return $string;
 }
Beispiel #17
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $result = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     $result['srcAddress'] = array('zipcode' => $sourceAddress->getZipcode(), 'country' => $sourceAddress->getCountryCode());
     if ($sourceAddress->getStatе()) {
         $result['srcAddress']['state'] = $sourceAddress->getStatе()->getCode();
     }
     $result['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
     if (empty($result['dstAddress']['country'])) {
         $result['dstAddress'] = null;
     } elseif (isset($result['dstAddress']['state'])) {
         /** @var \XLite\Model\Repo\State $repo */
         $repo = \XLite\Core\Database::getRepo('XLite\\Model\\State');
         $result['dstAddress']['state'] = $repo->getCodeById($result['dstAddress']['state']);
     }
     $result['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()) {
             $result['cod_enabled'] = true;
         }
     }
     return $result;
 }
Beispiel #18
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $result = array();
     $config = $this->getConfiguration();
     /** @var \XLite\Model\Repo\State $repo */
     $repo = \XLite\Core\Database::getRepo('XLite\\Model\\State');
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     $result['srcAddress'] = array('country' => $sourceAddress->getCountryCode(), 'zipcode' => $sourceAddress->getZipcode(), 'state' => $sourceAddress->getState()->getCode());
     $destinationAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
     if (null !== $destinationAddress) {
         $stateCode = $repo->getCodeById($destinationAddress['state']);
         $shippingAddress = $inputData->getOrder()->getProfile() ? $inputData->getOrder()->getProfile()->getShippingAddress() : null;
         $type = $shippingAddress && $shippingAddress->getType() ? $shippingAddress->getType() : $config->destinationType;
         $result['dstAddress'] = array('country' => $destinationAddress['country'], 'zipcode' => $destinationAddress['zipcode'], 'state' => $stateCode, 'type' => $type);
         $result['items'] = $this->getItems($inputData);
     }
     return array('package' => $result);
 }
Beispiel #19
0
 /**
  * Returns a list of shipping methods
  *
  * @return array
  */
 public function getShippingMethods()
 {
     return \XLite\Model\Shipping::getInstance()->getShippingMethods();
 }
Beispiel #20
0
 /**
  * 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);
         $data['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         $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_USPS' == $paymentMethod->getServiceName()) {
                 $data['cod_enabled'] = true;
             }
         }
     } else {
         $data = $inputData;
     }
     if (!empty($data['packages']) && isset($data['srcAddress']) && isset($data['dstAddress'])) {
         $this->setApiType($data['dstAddress']);
         $result['USERID'] = \XLite\Core\Config::getInstance()->CDev->USPS->userid;
         $result['packages'] = array();
         $result['cod_enabled'] = !empty($data['cod_enabled']);
         $result['max_weight'] = 0;
         foreach ($data['packages'] as $packKey => $package) {
             $result['max_weight'] = max($result['max_weight'], $package['weight']);
             $result['packages'][] = $this->{'prepareRequestData' . $this->getApiType()}($data, $packKey);
         }
     } else {
         $result = null;
     }
     return $result;
 }
Beispiel #21
0
 /**
  * Retrieve available shipping rates
  *
  * @return array
  */
 protected function retrieveRates()
 {
     return \XLite\Model\Shipping::getInstance()->getRates($this);
 }
Beispiel #22
0
 /**
  * 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);
         $data['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         $data['packages'][] = array('weight' => $inputData->getWeight(), 'subtotal' => $inputData->getSubtotal());
     } else {
         $data = $inputData;
     }
     if (isset($data['srcAddress']) && isset($data['dstAddress'])) {
         $this->setApiType($data['dstAddress']);
         $result['USERID'] = \XLite\Core\Config::getInstance()->CDev->USPS->userid;
         $result['packages'] = array();
         foreach ($data['packages'] as $packKey => $package) {
             $result['packages'][] = $this->{'prepareRequestData' . $this->getApiType()}($data, $packKey);
         }
     } else {
         $result = null;
     }
     return $result;
 }
Beispiel #23
0
 /**
  * Check if view should reload ajax-ly after page load (in case of online shippings)
  *
  * @return boolean
  */
 public function shouldDeferLoad()
 {
     return \XLite\Model\Shipping::getInstance()->hasOnlineProcessors();
 }
Beispiel #24
0
 /**
  * Prepare input data from order shipping modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier($modifier)
 {
     $data = array();
     if ('AU' == \XLite\Core\Config::getInstance()->Company->location_country) {
         $addrInfo = array();
         $addrInfo['from_postcode'] = \XLite\Core\Config::getInstance()->Company->location_zipcode;
         $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier);
         if (isset($dstAddress)) {
             $addrInfo['to_postcode'] = $dstAddress['zipcode'];
             $addrInfo['country_code'] = $dstAddress['country'];
             $data['packages'] = $this->getPackages($modifier);
             foreach ($data['packages'] as $key => $package) {
                 $data['packages'][$key] = array_merge($package, $addrInfo);
             }
         }
     }
     return $data;
 }
Beispiel #25
0
 /**
  * Prepare input data from order shipping modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier($modifier)
 {
     $result = array();
     /** @var \XLite\Model\Repo\State $repo */
     $repo = \XLite\Core\Database::getRepo('XLite\\Model\\State');
     $companyInfo = \XLite\Core\Config::getInstance()->Company;
     $stateCode = $repo->getCodeById($companyInfo->location_state);
     $result['srcAddress'] = array('country' => $companyInfo->location_country, 'zipcode' => $companyInfo->location_zipcode, 'state' => $stateCode);
     $destinationAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier);
     if (isset($destinationAddress)) {
         $stateCode = $repo->getCodeById($destinationAddress['state']);
         $shippingAddress = $modifier->getOrder()->getProfile() ? $modifier->getOrder()->getProfile()->getShippingAddress() : null;
         $type = $shippingAddress && $shippingAddress->getType() ? $shippingAddress->getType() : \XLite\Core\Config::getInstance()->XC->AuctionInc->destinationType;
         $result['dstAddress'] = array('country' => $destinationAddress['country'], 'zipcode' => $destinationAddress['zipcode'], 'state' => $stateCode, 'type' => $type);
         $result['items'] = $this->getItems($modifier);
     }
     return array('package' => $result);
 }
Beispiel #26
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $data = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     if ('AU' === $sourceAddress->getCountryCode()) {
         $addrInfo = array();
         $addrInfo['from_postcode'] = $sourceAddress->getZipcode();
         $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         if (null !== $dstAddress) {
             $addrInfo['to_postcode'] = $dstAddress['zipcode'];
             $addrInfo['country_code'] = $dstAddress['country'];
             $data['packages'] = $this->getPackages($inputData);
             foreach ($data['packages'] as $key => $package) {
                 $data['packages'][$key] = array_merge($package, $addrInfo);
             }
         }
     }
     return $data;
 }
Beispiel #27
0
 /**
  * Calculate shipping rates
  *
  * @return array(\XLite\Model\Shipping\Rate)
  */
 protected function calculateRates()
 {
     $rates = array();
     if ($this->isShippable()) {
         $rates = \XLite\Model\Shipping::getInstance()->getRates($this);
         uasort($rates, array($this, 'compareRates'));
     }
     return $rates;
 }
Beispiel #28
0
 /**
  * Set estimate destination
  *
  * @return void
  */
 protected function doActionSetDestination()
 {
     $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find(\XLite\Core\Request::getInstance()->country);
     if (\XLite\Core\Request::getInstance()->is_custom_state) {
         $state = new \XLite\Model\State();
         $state->setState(\XLite\Core\Request::getInstance()->state);
     } else {
         $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find(\XLite\Core\Request::getInstance()->state);
     }
     if ($country && $country->getEnabled() && $state && $state->getState() && \XLite\Core\Request::getInstance()->zipcode) {
         $address = $this->getCartProfile()->getShippingAddress();
         if (!$address) {
             $profile = $this->getCartProfile();
             $address = new \XLite\Model\Address();
             $address->setProfile($profile);
             $address->setIsShipping(true);
             $profile->addAddresses($address);
             \XLite\Core\Database::getEM()->persist($address);
         }
         $address->setCountry($country);
         $address->setState($state->getStateId() ? $state : $state->getState());
         $address->setZipcode(\XLite\Core\Request::getInstance()->zipcode);
         $address->update();
         $this->updateCart();
         $modifier = $this->getCart()->getModifier('shipping', 'SHIPPING');
         if ($modifier) {
             \XLite\Core\Event::updateCart(array('items' => array(), 'shipping_address' => \XLite\Model\Shipping::getInstance()->getDestinationAddress($modifier->getModifier())));
         }
         $this->valid = true;
         $this->setInternalRedirect();
     } else {
         \XLite\Core\TopMessage::addError('Shipping address is invalid');
         $this->valid = false;
     }
 }
Beispiel #29
0
 /**
  * Perform some actions at startup
  *
  * @return string
  */
 public static function init()
 {
     parent::init();
     // Register AustraliaPost shipping processor
     \XLite\Model\Shipping::getInstance()->registerProcessor('\\XLite\\Module\\CDev\\AustraliaPost\\Model\\Shipping\\Processor\\AustraliaPost');
 }
Beispiel #30
0
 /**
  * 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;
 }