Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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'));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Set $ignoreLongCalculations variable
  *
  * @param boolean $value Mode
  *
  * @return void
  */
 public static function setIgnoreLongCalculationsMode($value)
 {
     if (true == $value && \XLite\Module\CDev\XPaymentsConnector\Core\Iframe::getInstance()->useIframe() && \XLite\Core\Request::getInstance()->xpc_iframe) {
         // Workaround for checkCheckoutAction() method of controller.
         // Otherwise shippings might be not calculated
         $value = false;
     }
     parent::setIgnoreLongCalculationsMode($value);
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 /**
  * Get processor class object
  *
  * @return null|\XLite\Model\Shipping\Processor\AProcessor
  */
 public function getProcessorObject()
 {
     return \XLite\Model\Shipping::getProcessorObjectByProcessorId($this->getProcessor());
 }
Ejemplo n.º 8
0
 /**
  * Retrieve shipping adress from modifier
  * 
  * @return array
  */
 protected function getShippingAdress()
 {
     $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($this->inputData);
     return $this->getShippingAdressByDstAddressArray($dstAddress);
 }
Ejemplo n.º 9
0
 /**
  * Returns a list of shipping methods
  *
  * @return array
  */
 public function getShippingMethods()
 {
     return \XLite\Model\Shipping::getInstance()->getShippingMethods();
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
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');
 }
Ejemplo n.º 12
0
 /**
  * Check - build options or not
  *
  * @return boolean
  */
 protected function isBuildOptions()
 {
     return !\XLite\Model\Shipping::isIgnoreLongCalculations();
 }
Ejemplo n.º 13
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);
 }
Ejemplo n.º 14
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');
 }
Ejemplo n.º 15
0
 /**
  * Retrieve available shipping rates
  *
  * @return array
  */
 protected function retrieveRates()
 {
     return \XLite\Model\Shipping::getInstance()->getRates($this);
 }
Ejemplo n.º 16
0
 /**
  * doQuery
  *
  * lowlevel query
  *
  * @param mixed   $data        Array of prepared package data
  * @param boolean $ignoreCache Flag: if true then do not get rates from cache
  *
  * @return void
  */
 protected function doQuery($data, $ignoreCache)
 {
     $rates = array();
     $availableMethods = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findMethodsByProcessor($this->getProcessorId());
     $config = $this->getConfig();
     $XMLData = $this->getXMLData($data);
     try {
         if (!$ignoreCache) {
             $cachedRates = $this->getDataFromCache($XMLData);
         }
         if (isset($cachedRates)) {
             $result = $cachedRates;
         } elseif (\XLite\Model\Shipping::isIgnoreLongCalculations()) {
             // Ignore rates calculation
             return array();
         } else {
             $postURL = \XLite\Module\XC\CanadaPost\Core\API::getInstance()->getGetRatesEndpoint();
             $bouncer = new \XLite\Core\HTTP\Request($postURL);
             $bouncer->requestTimeout = 5;
             $bouncer->body = $XMLData;
             $bouncer->verb = 'POST';
             $bouncer->setHeader('Authorization', 'Basic ' . base64_encode($config->user . ':' . $config->password));
             $bouncer->setHeader('Accept', 'application/vnd.cpc.ship.rate-v2+xml');
             $bouncer->setHeader('Content-Type', 'application/vnd.cpc.ship.rate-v2+xml');
             $bouncer->setHeader('Accept-language', \XLite\Module\XC\CanadaPost\Core\API::ACCEPT_LANGUAGE_EN);
             if (\XLite\Module\XC\CanadaPost\Core\API::isOnBehalfOfAMerchant()) {
                 $bouncer->setHeader('Platform-id', \XLite\Module\XC\CanadaPost\Core\API::getInstance()->getPlatformId());
             }
             $response = $bouncer->sendRequest();
             $result = $response->body;
             if (200 == $response->code) {
                 $this->saveDataInCache($XMLData, $result);
             } else {
                 $this->errorMsg = sprintf('Error while connecting to the Canada Post host (%s)', $postURL);
             }
             if (\XLite\Core\Config::getInstance()->XC->CanadaPost->debug_enabled) {
                 // Save debug log
                 \XLite\Module\XC\CanadaPost\Core\API::logApiCall($postURL, 'Get Rates', $XMLData, $result);
             }
         }
         // Save communication log for test request only (ignoreCache is set for test requests only)
         if ($ignoreCache === true) {
             $this->apiCommunicationLog[] = array('post URL' => $postURL, 'request' => htmlentities($XMLData), 'response' => htmlentities(\XLite\Core\XML::getInstance()->getFormattedXML($result)));
         }
         $response = $this->parseResponse($result);
         if (!isset($this->errorMsg) && !isset($response['err_msg']) && !empty($response['services'])) {
             $conversionRate = \XLite\Module\XC\CanadaPost\Core\API::getCurrencyConversionRate();
             foreach ($response['services'] as $service) {
                 $rate = new \XLite\Model\Shipping\Rate();
                 $method = $this->getShippingMethod($service['service_code'], $availableMethods);
                 if (!isset($method)) {
                     // Unknown method received: add this to the database with disabled status
                     $this->addShippingMethod($service);
                 } elseif ($method->getEnabled()) {
                     // Method is registered and enabled
                     $rate->setMethod($method);
                     $rate->setBaseRate($service['rate'] * $conversionRate);
                     $rates[$service['service_code']] = $rate;
                 }
             }
         } elseif (!isset($this->errorMsg) || isset($response['err_msg'])) {
             $this->errorMsg = isset($response['err_msg']) ? $response['err_msg'] : ($this->errorMsg ?: 'Unknown error');
         }
     } catch (\Exception $e) {
         $this->errorMsg = $e->getMessage();
     }
     return $rates;
 }
Ejemplo n.º 17
0
 /**
  * Performs request to USPS server and returns array of rates
  *
  * @param array   $data        Array of request parameters
  * @param boolean $ignoreCache Flag: if true then do not get rates from cache
  *
  * @return array
  */
 protected function doQuery($data, $ignoreCache)
 {
     $result = null;
     $rates = array();
     $availableMethods = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findMethodsByProcessor($this->getProcessorId());
     if ($availableMethods) {
         $xmlData = $this->getXMLData($data);
         $currencyRate = doubleval(\XLite\Core\Config::getInstance()->CDev->USPS->currency_rate);
         $currencyRate = 0 < $currencyRate ? $currencyRate : 1;
         $postURL = $this->getApiURL() . '?API=' . $this->getApiName() . '&XML=' . urlencode(preg_replace('/>(\\s+)</', '><', $xmlData));
         try {
             if (!$ignoreCache) {
                 $cachedRate = $this->getDataFromCache($postURL);
             }
             if (isset($cachedRate)) {
                 // Get rates from cache
                 $result = $cachedRate;
             } elseif (\XLite\Model\Shipping::isIgnoreLongCalculations()) {
                 // Ignore rates calculation
                 return array();
             } else {
                 // Calculate rate
                 $bouncer = new \XLite\Core\HTTP\Request($postURL);
                 $bouncer->requestTimeout = 5;
                 $response = $bouncer->sendRequest();
                 if ($response && 200 == $response->code) {
                     $result = $response->body;
                     $this->saveDataInCache($postURL, $result);
                     if (\XLite\Core\Config::getInstance()->CDev->USPS->debug_enabled) {
                         \XLite\Logger::logCustom('USPS', var_export(array('Request URL' => $postURL, 'Request XML' => $xmlData, 'Response' => \XLite\Core\XML::getInstance()->getFormattedXML($result)), true));
                     }
                 } else {
                     $this->errorMsg = sprintf('Error while connecting to the USPS host (%s)', $this->getApiURL());
                 }
             }
             $response = isset($this->errorMsg) ? array() : $this->parseResponse($result);
             $this->apiCommunicationLog[] = array('request' => $postURL, 'xml' => htmlentities(preg_replace('/(USERID=")([^"]+)/', '\\1***', $xmlData)), 'response' => htmlentities(\XLite\Core\XML::getInstance()->getFormattedXML($result)));
             if (!isset($this->errorMsg) && !isset($response['err_msg']) && !empty($response['postage'])) {
                 foreach ($response['postage'] as $postage) {
                     $rate = new \XLite\Model\Shipping\Rate();
                     $method = $this->getShippingMethod($postage['CLASSID'], $availableMethods);
                     if (!isset($method)) {
                         // Unknown method received: add this to the database with disabled status
                         $method = $this->addShippingMethod($postage);
                     }
                     if ($method && $method->getEnabled()) {
                         // Method is registered and enabled
                         $rate->setMethod($method);
                         $codPrice = 0;
                         $rateValue = doubleval($postage['Rate']);
                         if (!$this->isStaticCODPrice() && isset($postage['SpecialServices'])) {
                             if (isset($postage['SpecialServices'][6]) && 'true' == $postage['SpecialServices'][6]['Available']) {
                                 // Shipping service supports COD
                                 $extraData = new \XLite\Core\CommonCell();
                                 $extraData->cod_supported = true;
                                 $extraData->cod_rate = ($rateValue + doubleval($postage['SpecialServices'][6]['Price'])) * $currencyRate;
                                 $rate->setExtraData($extraData);
                                 if ($data['cod_enabled']) {
                                     // Calculate COD fee if COD payment method is selected
                                     $codPrice = doubleval($postage['SpecialServices'][6]['Price']);
                                 }
                             }
                         } elseif ($this->isStaticCODPrice() && $this->isMethodSupportCOD($method)) {
                             $codStaticPrice = doubleval(\XLite\Core\Config::getInstance()->CDev->USPS->cod_price);
                             if (0 < $codStaticPrice) {
                                 // Shipping service supports COD
                                 $extraData = new \XLite\Core\CommonCell();
                                 $extraData->cod_supported = true;
                                 $extraData->cod_rate = ($rateValue + $codStaticPrice) * $currencyRate;
                                 $rate->setExtraData($extraData);
                                 if ($data['cod_enabled']) {
                                     // Calculate COD fee if COD payment method is selected
                                     $codPrice = $codStaticPrice;
                                 }
                             }
                         }
                         // Base rate is a sum of base rate and COD fee
                         $rate->setBaseRate(($rateValue + $codPrice) * $currencyRate);
                         if (isset($rates[$postage['MailService']])) {
                             // Multipackaging: sum base rate and COD fee for each rated packages
                             $rates[$postage['MailService']]->setBaseRate($rates[$postage['MailService']]->getBaseRate() + $rate->getBaseRate());
                             if ($rate->getExtraData()->cod_rate) {
                                 $extra = $rates[$postage['MailService']]->getExtraData();
                                 $extra->cod_rate = $extra->cod_rate + $rate->getExtraData()->cod_rate;
                                 $rates[$postage['MailService']]->setExtraData($extra);
                             }
                         } else {
                             $rates[$postage['MailService']] = $rate;
                         }
                     }
                 }
             } elseif (!isset($this->errorMsg)) {
                 $this->errorMsg = isset($response['err_msg']) ? $response['err_msg'] : 'Unknown error';
             }
         } catch (\Exception $e) {
             $this->errorMsg = 'Exception: ' . $e->getMessage();
         }
     }
     return $rates;
 }
Ejemplo n.º 18
0
 /**
  * Recalculate order
  *
  * @return void
  */
 protected function doActionRecalculate()
 {
     if ($this->isOrderEditable()) {
         // Set ignoreLongCalculations mode for shipping rates gathering
         \XLite\Model\Shipping::setIgnoreLongCalculationsMode(false);
         // Initialize temprorary order
         $order = static::getTemporaryOrder($this->getOrder()->getOrderId(), true);
         // Update order items list
         $this->updateOrderItems($order);
         // Perform 'recalculate' action via model form
         $this->getOrderForm()->performAction('recalculate');
         if (\XLite\Core\Request::getInstance()->isAJAX()) {
             $this->displayRecalculateData($order);
             $this->displayRecalculateShippingData($order);
             $this->restoreFormId();
             $this->removeTemporaryOrder($order);
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Get cache parameters
  *
  * @return array
  */
 protected function getCacheParameters()
 {
     $list = parent::getCacheParameters();
     $auth = \XLite\Core\Auth::getInstance();
     if ($auth->isLogged()) {
         $profile = $auth->getProfile();
         // Membership as a parameter (wholesale and other prices)
         $list[] = $profile->getMembership() ? $profile->getMembership()->getMembershipId() : '-';
         // Shipping address zone as a parameter (taxes amount)
         foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Zone')->findApplicableZones(\XLite\Model\Shipping::prepareAddressData($profile->getShippingAddress())) as $zone) {
             $list[] = $zone->getZoneId();
         }
     }
     // If the cart is changed the widget content must be recalculated
     $list[] = $this->getCart()->getItemsFingerprint();
     // If some of the registered widget/request parameters are changed
     // the widget content must be recalculated
     foreach ($this->defineCachedParams() as $name) {
         $list[] = $this->getRequestParamValue($name) ?: (($widgetParam = $this->getWidgetParams($name)) ? $widgetParam->value : '');
     }
     return $list;
 }
Ejemplo n.º 20
0
 /**
  * Internal unconditional getRates() part
  * 
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData   Shipping order modifier or array of data for request
  * @param boolean                              $ignoreCache Flag: if true then do not get rates from cache OPTIONAL
  *
  * @return array
  */
 protected function getGuaranteedRates($inputData, $ignoreCache = false)
 {
     $rates = array();
     $cachedRate = null;
     if (!$ignoreCache) {
         $cachedRate = $this->getDataFromCache($this->getGuaranteedCacheKey($inputData));
     }
     if (null !== $cachedRate) {
         $rates = $cachedRate;
     } elseif (\XLite\Model\Shipping::isIgnoreLongCalculations()) {
         $rates = array();
     } else {
         $rates = $this->getGuaranteedRatesFromServer($inputData);
         if ($rates) {
             // Force translations lazy loading
             foreach ($rates as $rate) {
                 $rate->getMethod()->getName();
             }
             $this->saveDataInCache($this->getGuaranteedCacheKey($inputData), $rates, static::CREATE_ORDER_TTL);
         }
     }
     return $rates;
 }
Ejemplo n.º 21
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();
 }
Ejemplo n.º 22
0
 /**
  * Do request to AustraliaPost API and receive response
  *
  * @param string  $type        Request type
  * @param array   $params      Array of parameters
  * @param boolean $ignoreCache Flag: ignore cache
  *
  * @return array|null
  */
 protected function doRequest($type, $params = array(), $ignoreCache = false)
 {
     $result = null;
     $requestType = $this->getApiRequestType($type);
     $config = $this->getConfiguration();
     $methodName = 'getRequestData' . $type;
     $data = array();
     if (method_exists($this, $methodName)) {
         // Call method to prepare request data
         $data = $this->{$methodName}($params);
     }
     // Validate request data
     if ($this->validateRequestData($requestType, $data)) {
         // Prepare post data
         $postData = array();
         foreach ($data as $key => $value) {
             if (in_array($key, array('option_code', 'suboption_code'))) {
                 foreach ($value as $opcode) {
                     $postData[] = sprintf('%s=%s', $key, $opcode);
                 }
             } else {
                 $postData[] = sprintf('%s=%s', $key, $value);
             }
         }
         $postURL = $this->getApiURL() . $requestType['uri'] . '.json?' . implode('&', $postData);
         if (!$ignoreCache) {
             // Try to get cached result
             $cachedRate = $this->getDataFromCache($postURL . $this->getApiKey());
         }
         if (isset($cachedRate)) {
             // Get result from cache
             $result = $cachedRate;
         } elseif (\XLite\Model\Shipping::isIgnoreLongCalculations()) {
             // Ignore rates calculation
             return array();
         } else {
             // Get result from AustraliaPost server
             try {
                 $headers = array('AUTH-KEY: ' . $this->getApiKey());
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $postURL);
                 curl_setopt($ch, CURLOPT_HEADER, false);
                 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_TIMEOUT, 15);
                 if ($this->isTestMode()) {
                     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                 }
                 $response = curl_exec($ch);
                 if (!empty($response)) {
                     $result = json_decode($response, true);
                     if (!empty($result['error'])) {
                         $this->setError($result['error']['errorMessage']);
                     } else {
                         $this->saveDataInCache($postURL . $this->getApiKey(), $result);
                     }
                 } else {
                     $this->setError(sprintf('Error while connecting to the AustraliaPost host (%s)', $postURL));
                 }
                 if ($ignoreCache === true) {
                     // Prepare data to display on Test AustraliaPost page
                     $this->addApiCommunicationMessage(array('request_url' => $postURL, 'request_data' => $data, 'response' => $response, 'response_parsed' => $result));
                 }
                 if ($config->debug_enabled) {
                     $this->log(array('postURL' => $postURL, 'data' => $data, 'result' => $result));
                 }
             } catch (\Exception $e) {
                 $this->setError($e->getMessage());
             }
         }
     }
     return $result;
 }
Ejemplo n.º 23
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');
 }
Ejemplo n.º 24
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;
     }
 }
Ejemplo n.º 25
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;
 }
Ejemplo n.º 26
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');
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
0
 /**
  * Get address for zone calculator
  *
  * @return array
  */
 protected function getAddress()
 {
     $address = null;
     $addressObj = $this->getOrderAddress();
     if ($addressObj) {
         // Profile is exists
         $address = \XLite\Model\Shipping::prepareAddressData($addressObj);
     }
     if (!isset($address)) {
         $address = $this->getDefaultAddress();
     }
     return $address;
 }
Ejemplo n.º 29
0
 /**
  * Get default customer address for taxes calculation
  *
  * @return array
  */
 protected function getDefaultAddress()
 {
     return \XLite\Model\Shipping::getDefaultAddress();
 }
Ejemplo n.º 30
0
Archivo: Main.php Proyecto: kingsj/core
 /**
  * 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');
 }