/**
  * Display a form for the user to choose Store Pickup or
  * enter a shipping address and process the input
  *
  * @return void
  */
 public function actionShipping()
 {
     $this->publishJS('shipping');
     $this->publishJS('zippo');
     $this->layout = '/layouts/checkout';
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     $arrObjAddresses = CustomerAddress::getActiveAddresses();
     // In some cases an address may be rejected.
     // TODO: it's not ideal to rely on the client to tell us whether to
     // display an error or not.
     if (CPropertyValue::ensureBoolean(Yii::app()->request->getQuery('error-destination')) === true) {
         $message = Yii::t('checkout', 'Sorry, we cannot ship to this destination');
         $this->checkoutForm->addError('shipping', $message);
     }
     // if the logged in customer has at least one address on file
     // take them to the page where they can select it
     if (count($arrObjAddresses) > 0) {
         if (isset($message)) {
             Yii::app()->user->setFlash('error', $message);
         }
         $this->redirect($this->createAbsoluteUrl('/checkout/shippingaddress'));
     }
     if (isset($_POST['MultiCheckoutForm'])) {
         $this->checkoutForm->attributes = $_POST['MultiCheckoutForm'];
         $this->checkoutForm->setScenario('Shipping');
         // store pickup checkbox is checked
         if (isset($_POST['storePickupCheckBox']) && $_POST['storePickupCheckBox'] == 1) {
             $this->checkoutForm->fillFieldsForStorePickup();
             $this->checkoutForm->setScenario('StorePickup');
             if ($this->checkoutForm->validate() && $this->checkoutForm->updateAddressId()) {
                 // Update the shipping scenarios based on the new address.
                 $this->checkoutForm->saveFormToSession();
                 Shipping::updateCartScenariosInSession();
                 // Update the shopping cart taxes.
                 Yii::app()->shoppingcart->setTaxCodeByCheckoutForm($this->checkoutForm);
                 // Update shipping. If in-store pickup was chosen then we need to
                 // ensure the cart shipping values are updated.
                 $objShipping = CartShipping::getOrCreateCartShipping();
                 if ($objShipping->hasErrors() === false) {
                     $objShipping->updateShipping();
                     $this->checkoutForm->addErrors($objShipping->getErrors());
                 } else {
                     $this->checkoutForm->addErrors($objShipping->getErrors());
                 }
                 // save the passed scenario
                 $this->checkoutForm->passedScenario = $this->checkoutForm->getScenario();
                 // Go straight to payment
                 $this->redirect($this->createUrl('/checkout/final'));
             }
         } else {
             // Check whether the in-store pickup was previously selected.
             // If it was, unset it.
             if ($this->checkoutForm->isStorePickupSelected()) {
                 $this->checkoutForm->shippingProvider = null;
                 $this->checkoutForm->shippingPriority = null;
                 $this->checkoutForm->pickupFirstName = null;
                 $this->checkoutForm->pickupLastName = null;
             }
             $this->checkoutForm->contactFirstName = $this->checkoutForm->shippingFirstName;
             $this->checkoutForm->contactLastName = $this->checkoutForm->shippingLastName;
             $this->checkoutForm->shippingPostal = strtoupper($this->checkoutForm->shippingPostal);
         }
         // validate before we can progress
         if ($this->checkoutForm->validate()) {
             $this->checkoutForm->saveFormToSession();
             // update the cart
             if ($this->checkoutForm->updateAddressId('shipping')) {
                 // Save the passed scenario.
                 $this->checkoutForm->passedScenario = $this->checkoutForm->getScenario();
                 $this->checkoutForm->saveFormToSession();
                 // Update the shipping scenarios based on the new address.
                 Shipping::updateCartScenariosInSession();
                 // Update the cart shipping. Do not update the taxes yet -
                 // it is possible user has entered an invalid tax
                 // destination. The tax destinations are checking on the
                 // shippingoptions page.
                 // Update shipping. If in-store pickup was chosen then we need to
                 // ensure the cart shipping values are updated.
                 $objShipping = CartShipping::getOrCreateCartShipping();
                 if ($objShipping->hasErrors() === false) {
                     $objShipping->updateShipping();
                     $this->checkoutForm->addErrors($objShipping->getErrors());
                 } else {
                     $this->checkoutForm->addErrors($objShipping->getErrors());
                 }
                 $this->redirect($this->createUrl('/checkout/shippingoptions'));
             }
         }
     } elseif (isset($_GET['address_id'])) {
         $result = $this->checkoutForm->fetchCustomerShippingAddress($_GET['address_id']);
         if ($result === false) {
             $this->redirect($this->createAbsoluteUrl("/checkout/shippingaddress"));
         }
     }
     $this->checkoutForm->saveFormToSession();
     if (empty($this->checkoutForm->shippingCountry) === false) {
         // Update shipping. If in-store pickup was chosen then we need to
         // ensure the cart shipping values are updated.
         $objShipping = CartShipping::getOrCreateCartShipping();
         if ($objShipping->hasErrors() === false) {
             $objShipping->updateShipping();
             $this->checkoutForm->addErrors($objShipping->getErrors());
         } else {
             $this->checkoutForm->addErrors($objShipping->getErrors());
         }
     }
     $this->render('shipping', array('model' => $this->checkoutForm, 'error' => $this->formatErrors()));
 }