/**
  * Return the options required by ConfirmationShippingEstimator.js
  * which is registered anytime the confirmation page is rendered
  *
  * @return array
  */
 private function _getShippingEstimatorOptions()
 {
     $selectedCartScenario = Shipping::getSelectedCartScenarioFromSession();
     $wsShippingEstimatorOptions = WsShippingEstimator::getShippingEstimatorOptions(array($selectedCartScenario), $this->checkoutForm->shippingProvider, $this->checkoutForm->shippingPriority, $this->checkoutForm->shippingCity, $this->checkoutForm->shippingStateCode, $this->checkoutForm->shippingCountryCode);
     $wsShippingEstimatorOptions['redirectToShippingOptionsUrl'] = Yii::app()->getController()->createUrl('shippingoptions');
     return $wsShippingEstimatorOptions;
 }
예제 #2
0
 /**
  * This is the method used by the advanced cart and checkout to retrieve
  * shipping options and their rates for the shipping estimator.
  * @return string JSON encoded array of shipping options ordered by price.
  */
 public function actionGetShippingRates()
 {
     $checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     // If no CheckoutForm is posted, then the checkoutForm stored in the
     // session is used.  This is completely valid when we want updated
     // rates, but haven't modified (or perhaps don't know) the shipping
     // address.
     if (isset($_POST['CheckoutForm'])) {
         $checkoutForm->attributes = $_POST['CheckoutForm'];
     }
     // Transform the postcode as required by the shipping modules.
     // TODO Can we move this?
     $checkoutForm->shippingPostal = strtoupper(str_replace(' ', '', $checkoutForm->shippingPostal));
     // Minimal requirements for shipping: just address details.
     $checkoutForm->scenario = 'MinimalShipping';
     if ($checkoutForm->validate() === false) {
         return $this->renderJSON(array('result' => 'error', 'errors' => $checkoutForm->getErrors()));
     }
     try {
         $arrCartScenario = Shipping::getCartScenarios($checkoutForm);
     } catch (Exception $e) {
         return $this->renderJSON(array('result' => 'error', 'errormsg' => $e->getMessage()));
     }
     // Get the shipping estimator JavaScript options.
     $wsShippingEstimatorOptions = WsShippingEstimator::getShippingEstimatorOptions($arrCartScenario, $checkoutForm->shippingProvider, $checkoutForm->shippingPriority, $checkoutForm->shippingCity, $checkoutForm->shippingStateCode, $checkoutForm->shippingCountryCode);
     $shippingEstimatorMessage = findWhere($wsShippingEstimatorOptions['messages'], array('code' => 'WARN'));
     if ($shippingEstimatorMessage !== null) {
         $message = Yii::t('checkout', 'Your previous shipping selection is no longer available. Please choose an available shipping option.');
         Yii::app()->user->setFlash('error', $message);
     }
     // Save to session.
     Shipping::saveCartScenariosToSession($arrCartScenario);
     MultiCheckoutForm::saveToSession($checkoutForm);
     // Save to the database.
     $objShipping = CartShipping::getOrCreateCartShipping();
     $objShipping->updateShipping();
     return $this->renderJSON(array('result' => 'success', 'wsShippingEstimatorOptions' => $wsShippingEstimatorOptions, 'taxModeChangedMessage' => Yii::app()->user->getFlash('taxModeChange', null)));
 }