/**
  * Run the widget. Renders the shipping estimator lines on the page.
  */
 public function run()
 {
     // Required assets.
     $assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets', false, -1, true);
     Yii::app()->clientScript->registerScriptFile($assets . '/js/WsShippingEstimator.js');
     $pathToZippo = Yii::getPathOfAlias('ext') . DIRECTORY_SEPARATOR . 'wsadvcheckout' . DIRECTORY_SEPARATOR . 'assets';
     $assets = Yii::app()->getAssetManager()->publish($pathToZippo, false, -1, true);
     Yii::app()->clientScript->registerScriptFile($assets . '/zippo.js');
     $checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     // We may wish to update the shipping options right away if we know the
     // cart has changed.
     $updateOnLoad = false;
     if ($this->updateShippingOptions) {
         // This check for shippingCountry being null is a workaround to fix
         // WS-3180. When shippingCountry is null, we need to update the
         // shipping estimates *now* because they will not be updated by the
         // JavaScript (since the JavaScript in WsShippingEstimator requires
         // country to be set). The reason we need to do this is because
         // shippingCountry may be null when in-store pickup has been
         // chosen.
         // TODO: Fix this in WsShippingEstimator and remove this workaround.
         if (empty($checkoutForm->shippingCountry) || empty($checkoutForm->shippingPostal)) {
             Shipping::updateCartScenariosInSession();
         } else {
             $updateOnLoad = true;
         }
     }
     // Use the shipping scenarios and shipping address in the session.
     $arrCartScenario = Shipping::loadCartScenariosFromSession();
     $wsShippingEstimatorOptions = self::getShippingEstimatorOptions($arrCartScenario, $checkoutForm->shippingProvider, $checkoutForm->shippingPriority, $checkoutForm->shippingCity, $checkoutForm->shippingStateCode, $checkoutForm->shippingCountryCode, $updateOnLoad);
     $selectedCartScenario = Shipping::getSelectedCartScenarioFromSession();
     if ($selectedCartScenario !== null) {
         $formattedShippingPrice = $selectedCartScenario['formattedShippingPrice'];
         $formattedCartTax = $selectedCartScenario['formattedCartTax'];
     } else {
         $formattedShippingPrice = null;
         $formattedCartTax = null;
     }
     $this->render('_shippingestimator', array('countries' => CHtml::listData(Country::getShippingCountries(), 'code', 'country'), 'formattedShippingPrice' => $formattedShippingPrice, 'formattedCartTax' => $formattedCartTax, 'shippingCountryCode' => $wsShippingEstimatorOptions['shippingCountryCode'], 'shippingCountryName' => $wsShippingEstimatorOptions['shippingCountryName'], 'shippingPostal' => $checkoutForm->shippingPostal, 'wsShippingEstimatorOptions' => CJSON::encode($wsShippingEstimatorOptions), 'cssClass' => self::CSS_CLASS));
 }
 public function actionConfirmation()
 {
     // We should only be in here if someone has chosen a SIM.
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     $this->layout = '/layouts/checkout-confirmation';
     $objCart = Yii::app()->shoppingcart;
     $error = null;
     if (isset($_POST['MultiCheckoutForm'])) {
         $this->checkoutForm->attributes = $_POST['MultiCheckoutForm'];
         if ($objCart->shipping->isStorePickup) {
             $this->checkoutForm->setScenario('ConfirmationStorePickup');
         } else {
             $this->checkoutForm->setScenario('ConfirmationSim');
         }
         $isFormValid = $this->checkoutForm->updateCartCustomerId() && $this->checkoutForm->validate();
         if ($isFormValid && Yii::app()->shoppingcart->wasCartModified === false) {
             // our form is valid and the cart items are as we expect, continue
             self::executeCheckoutProcessInit();
             $this->runPaymentSim();
         } else {
             $this->layout = '/layouts/checkout-confirmation';
             $this->render('confirmation', array('model' => $this->checkoutForm, 'cart' => $objCart, 'error' => $this->formatErrors(), 'shippingEstimatorOptions' => $this->_getShippingEstimatorOptions(), 'recalculateShippingOnLoad' => Yii::app()->shoppingcart->wasCartModified));
         }
     } else {
         $orderId = Yii::app()->getRequest()->getQuery('orderId');
         $errorNote = Yii::app()->getRequest()->getQuery('errorNote');
         if (isset($errorNote) && isset($orderId)) {
             // Cancelled/Declined simple integration transaction.
             $objCart = Cart::LoadByIdStr($orderId);
             if (stripos($errorNote, 'cancel') !== false) {
                 // Cancelled.
                 $translatedErrorNote = Yii::t('checkout', 'You <strong>cancelled</strong> your payment.');
             } else {
                 // Declined.
                 $translatedErrorNote = Yii::t('checkout', 'There was an issue with your payment.') . '<br><br><strong>' . $errorNote . '</strong><br><br>';
                 $translatedErrorNote .= Yii::t('checkout', 'Try re-entering your payment details or contact us at {email} or {phone}', array('{email}' => _xls_get_conf('EMAIL_FROM'), '{phone}' => _xls_get_conf('STORE_PHONE')));
             }
             $this->checkoutForm->addErrors(array('note' => $translatedErrorNote));
         }
         $this->render('confirmation', array('model' => $this->checkoutForm, 'cart' => $objCart, 'shippingEstimatorOptions' => $this->_getShippingEstimatorOptions(), 'error' => $this->formatErrors()));
     }
 }
Exemplo n.º 3
0
 /**
  * Did the payment have a subform?
  *
  * @return bool
  */
 public function hasSubForm()
 {
     $form = MultiCheckoutForm::loadFromSessionOrNew();
     $objModule = Modules::LoadByName($this->payment_module);
     return array_key_exists($objModule->id, $form->getAlternativePaymentMethodsThatUseSubForms());
 }
Exemplo n.º 4
0
 /**
  * Apply a promo code to the cart and return an array indicating what happened.
  * @param string $strPromoCode The promocode.
  * @return array An array indicating what happened.
  *	['success'] boolean Whether the promo code was applied.
  *	['action'] string Recommended action: alert|error|triggerCalc|success.
  *	['message'] string A message to display.
  */
 protected function applyPromoCodeModal($strPromoCode)
 {
     if (Yii::app()->shoppingcart->PromoCode !== null) {
         return array('success' => false, 'action' => 'alert', 'message' => Yii::t('global', 'Only one promo code can be applied'));
     }
     $objPromoCode = new PromoCode();
     $objPromoCode->code = $strPromoCode;
     $objPromoCode->setScenario('checkout');
     if ($objPromoCode->validate() === false) {
         $arrErrors = $objPromoCode->getErrors();
         return array('success' => false, 'action' => 'error', 'message' => $arrErrors['code'][0]);
     }
     $objPromoCode = PromoCode::LoadByCode($strPromoCode);
     Yii::app()->shoppingcart->applyPromoCode($objPromoCode);
     // See if this promo code is supposed to turn on free shipping.
     // This runs AFTER validate() so if we get here, it means that any
     // criteria have passed. So just apply and refresh the shipping list.
     if ($objPromoCode->Shipping) {
         // Update the shipping selection to use the free shipping module.
         $objFreeShipping = Modules::model()->freeshipping()->find();
         if ($objFreeShipping !== null) {
             $checkoutForm = MultiCheckoutForm::loadFromSession();
             if ($checkoutForm !== null) {
                 try {
                     $arrCartScenario = Shipping::getCartScenarios($checkoutForm);
                 } catch (Exception $e) {
                     $arrCartScenario = null;
                 }
                 if ($arrCartScenario !== null) {
                     $freeShippingScenario = findWhere($arrCartScenario, array('providerId' => $objFreeShipping->id));
                     $checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
                     $checkoutForm->shippingProvider = $freeShippingScenario['providerId'];
                     $checkoutForm->shippingPriority = $freeShippingScenario['priorityLabel'];
                     MultiCheckoutForm::saveToSession($checkoutForm);
                 }
             }
         }
         return array('success' => true, 'action' => 'triggerCalc', 'message' => Yii::t('global', 'Congratulations! This order qualifies for Free Shipping!'));
     }
     return array('success' => true, 'action' => 'success');
 }