Пример #1
0
 private function getCartPageResponse()
 {
     $this->addBreadCrumb($this->translate('_my_session'), $this->router->createUrlFromRoute($this->request->get('return'), true));
     $this->order->setUser($this->user);
     $this->order->loadItemData();
     $response = new ActionResponse();
     if ($result = $this->order->updateToStock()) {
         $response->set('changes', $result);
     }
     $options = $this->getItemOptions();
     $currency = Currency::getValidInstanceByID($this->request->get('currency', $this->application->getDefaultCurrencyCode()), Currency::LOAD_DATA);
     $form = $this->buildCartForm($this->order, $options);
     if ($this->isTosInCartPage()) {
         $form->set('tos', $this->session->get('tos'));
     }
     if ($this->config->get('ENABLE_SHIPPING_ESTIMATE')) {
         $this->loadLanguageFile('User');
         if ($this->estimateShippingCost()) {
             //$this->order->getTotal(true);
             $response->set('isShippingEstimated', true);
         }
         $address = $this->order->shippingAddress->get();
         foreach (array('countryID' => 'country', 'stateName' => 'state_text', 'postalCode' => 'postalCode', 'city' => 'city') as $addressKey => $formKey) {
             $form->set('estimate_' . $formKey, $address->{$addressKey}->get());
         }
         if ($address->state->get() && $address->state->get()->getID()) {
             $form->set('estimate_state_select', $address->state->get()->getID());
         }
         $response->set('countries', $this->getCountryList($form));
         $response->set('states', $this->getStateList($form->get('estimate_country')));
         $hideConf = (array) $this->config->get('SHIP_ESTIMATE_HIDE_ENTRY');
         $hideForm = !empty($hideConf['UNREGISTERED']) && $this->user->isAnonymous() || !empty($hideConf['ALL_REGISTERED']) && !$this->user->isAnonymous() || !empty($hideConf['REGISTERED_WITH_ADDRESS']) && !$this->user->isAnonymous() && !$this->user->defaultBillingAddress->get() || !$this->order->isShippingRequired() || $this->order->isMultiAddress->get();
         $response->set('hideShippingEstimationForm', $hideForm);
     }
     $orderArray = $this->order->toArray();
     $itemsById = array();
     foreach (array('cartItems', 'wishListItems') as $type) {
         if (!empty($orderArray[$type])) {
             foreach ($orderArray[$type] as &$item) {
                 $itemsById[$item['ID']] =& $item;
             }
         }
     }
     $response->set('cart', $orderArray);
     $response->set('itemsById', $itemsById);
     $response->set('form', $form);
     $response->set('return', $this->request->get('return'));
     $response->set('currency', $currency->getID());
     $response->set('options', $options['visible']);
     $response->set('moreOptions', $options['more']);
     $response->set('orderTotal', $currency->getFormattedPrice($this->order->getTotal()));
     $response->set('expressMethods', $this->application->getExpressPaymentHandlerList(true));
     $response->set('isCouponCodes', DiscountCondition::isCouponCodes());
     $response->set('isOnePageCheckout', $this->config->get('CHECKOUT_METHOD') == 'CHECKOUT_ONEPAGE' && !$this->order->isMultiAddress->get() && !$this->session->get('noJS'));
     $this->order->getSpecification()->setFormResponse($response, $form);
     SessionOrder::getOrder()->getShoppingCartItems();
     return $response;
 }
Пример #2
0
 private function mergeOrder()
 {
     // load the last un-finalized order by this user
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()));
     $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'dateCreated'), 'DESC');
     $f->setLimit(1);
     $s = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
     if (!$this->order->user->get() || $this->order->user->get()->getID() == $this->user->getID()) {
         if ($s->size()) {
             $order = $s->get(0);
             if ($this->order->getID() != $order->getID()) {
                 $sessionOrder = SessionOrder::getOrder();
                 $order->loadItems();
                 $order->merge($sessionOrder);
                 $order->save();
                 SessionOrder::setOrder($order);
                 $this->order->delete();
             }
         } else {
             if ($this->order->getID()) {
                 $this->order->setUser($this->user);
                 SessionOrder::save($this->order);
             }
         }
     }
 }
Пример #3
0
 public function __get($name)
 {
     if ($inst = parent::__get($name)) {
         return $inst;
     }
     switch ($name) {
         case 'order':
             ClassLoader::import('application.model.order.SessionOrder');
             $this->order = SessionOrder::getOrder();
             // check if order currency matches the request currency
             if (!$this->order->currency->get() || $this->order->currency->get()->getID() != $this->getRequestCurrency()) {
                 $this->order->changeCurrency(Currency::getInstanceByID($this->getRequestCurrency()));
             }
             return $this->order;
             break;
         default:
             break;
     }
 }
Пример #4
0
 /**
  *	@role login
  */
 public function completeExternal()
 {
     if (SessionOrder::getOrder()->getID() != $this->request->get('id')) {
         SessionOrder::destroy();
     }
     $order = CustomerOrder::getInstanceById($this->request->get('id'), CustomerOrder::LOAD_DATA);
     if ($order->user->get() != $this->user) {
         throw new ApplicationException('Invalid order');
     }
     $this->session->set('completedOrderID', $order->getID());
     return new ActionRedirectResponse('checkout', 'completed');
 }