Example #1
0
 /**
  * Save shipping address to current quote using onepage model
  *
  * @return null
  */
 public function saveShippingAddressAction()
 {
     if (!$this->getRequest()->isPost()) {
         $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR);
         return;
     }
     try {
         $this->_initCheckout();
         $data = $this->getRequest()->getPost('shipping', array());
         array_walk_recursive($data, create_function('&$val', '$val = trim($val);'));
         if (!empty($data['region']) && isset($data['country_id'])) {
             $region = Mage::getModel('directory/region')->loadByCode($data['region'], $data['country_id']);
             if ($region && $region->getId()) {
                 $data['region_id'] = $region->getId();
             }
         }
         $result = $this->_checkout->saveShipping($data);
         if (!isset($result['error'])) {
             $this->_message($this->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS);
         } else {
             if (!is_array($result['message'])) {
                 $result['message'] = array($result['message']);
             }
             $this->_message(implode('. ', $result['message']), self::MESSAGE_STATUS_ERROR);
         }
     } catch (Mage_Core_Exception $e) {
         $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
         Mage::logException($e);
     } catch (Exception $e) {
         $this->_message($this->__('Unable to save shipping address.'), self::MESSAGE_STATUS_ERROR);
         Mage::logException($e);
     }
 }
 /**
  * Save shipping address to current quote using onepage model
  *
  * @return void
  */
 public function saveShippingAddressAction()
 {
     if (!$this->getRequest()->isPost()) {
         $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR);
         return;
     }
     try {
         $this->_initCheckout();
         $data = $this->getRequest()->getPost('shipping', array());
         $result = $this->_checkout->saveShipping($data);
         if (!isset($result['error'])) {
             $this->_message($this->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS);
         } else {
             if (!is_array($result['message'])) {
                 $result['message'] = array($result['message']);
             }
             $this->_message(implode('. ', $result['message']), self::MESSAGE_STATUS_ERROR);
         }
     } catch (Mage_Core_Exception $e) {
         $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
     } catch (Exception $e) {
         $this->_message($this->__('Unable to save shipping address.'), self::MESSAGE_STATUS_ERROR);
         Mage::logException($e);
     }
 }