Example #1
0
 public function setSingleAddress()
 {
     $f = new ARUpdateFilter(new EqualsCond(new ARFieldHandle('OrderedItem', 'customerOrderID'), $this->order->getID()));
     $f->addModifier('OrderedItem.shipmentID', new ARExpressionHandle('NULL'));
     ActiveRecordModel::updateRecordSet('OrderedItem', $f);
     $this->order->isMultiAddress->set(false);
     $this->order->loadAll();
     $this->order->mergeItems();
     $this->order->resetShipments();
     SessionOrder::save($this->order);
     $this->order->deleteRelatedRecordSet('Shipment');
     return new ActionRedirectResponse('order', 'index');
 }
Example #2
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;
     }
 }
Example #3
0
 public static function setOrder(CustomerOrder $order)
 {
     $session = new Session();
     $session->set('CustomerOrder', $order->getID());
     $currency = $order->getCurrency();
     $currID = $currency->getID();
     $total = $order->getTotal();
     $orderArray = array('total' => array($currID => $total));
     $orderArray['formattedTotal'] = array($currID => $currency->getFormattedPrice($orderArray['total'][$currID]));
     $orderArray['basketCount'] = $order->getShoppingCartItemCount();
     $orderArray['currencyID'] = $currID;
     $isOrderable = $order->isOrderable();
     $orderArray['isOrderable'] = is_bool($isOrderable) ? $isOrderable : false;
     $items = array();
     foreach ($order->getPurchasedItems() as $item) {
         $items[] = $item->toArray();
     }
     $orderArray['items'] = new RuleOrderContainer($items);
     $orderArray['items']->setCoupons($order->getCoupons());
     $orderArray['items']->setTotal($total);
     $session->set('orderData', $orderArray);
     self::$instance = $order;
 }
Example #4
0
 public function processCheckoutRegistration()
 {
     ActiveRecordModel::beginTransaction();
     $validator = $this->buildValidator();
     if (!$validator->isValid()) {
         $action = $this->request->get('regType') == 'register' ? 'registerAddress' : 'checkout';
         return new ActionRedirectResponse('user', $action, array('query' => array('return' => $this->request->get('return'))));
     }
     // create user account
     $user = $this->createUser($this->request->get('password'), 'billing_');
     // create billing and shipping address
     $address = $this->createAddress('billing_');
     $billingAddress = BillingAddress::getNewInstance($user, $address);
     $billingAddress->save();
     $shippingAddress = ShippingAddress::getNewInstance($user, $this->request->get('sameAsBilling') ? clone $address : $this->createAddress('shipping_'));
     $shippingAddress->save();
     $user->defaultShippingAddress->set($shippingAddress);
     $user->defaultBillingAddress->set($billingAddress);
     $user->save();
     // set order addresses
     $this->order->billingAddress->set($billingAddress->userAddress->get());
     $this->order->loadItems();
     if ($this->order->isShippingRequired()) {
         $this->order->shippingAddress->set($shippingAddress->userAddress->get());
     }
     $this->order->save();
     $this->order->setUser($user);
     SessionOrder::save($this->order);
     ActiveRecordModel::commit();
     if ($return = $this->request->get('return')) {
         return new RedirectResponse($this->router->createUrlFromRoute($return));
     } else {
         return new ActionRedirectResponse('checkout', 'shipping');
     }
 }
Example #5
0
 public function getBusinessRuleController()
 {
     if (!$this->businessRuleController) {
         $context = new BusinessRuleContext();
         if ($items = SessionOrder::getOrderItems()) {
             $context->setOrder($items);
         }
         if (SessionUser::getUser()) {
             $context->setUser(SessionUser::getUser());
         }
         $this->businessRuleController = new BusinessRuleController($context);
         if ($this->isBackend()) {
             $this->businessRuleController->disableDisplayDiscounts();
         }
     }
     return $this->businessRuleController;
 }
Example #6
0
 public function doSelectBillingAddress()
 {
     $this->order->loadAll();
     $this->request->set('step', 'billing');
     $this->initAnonUser();
     $shipments = $this->order->getShipments();
     if (!$this->user->isAnonymous()) {
         $this->separateBillingAndShippingAddresses();
     }
     if (!$this->request->get('sameAsShipping') && $this->order->shippingAddress->get() && $this->order->billingAddress->get() && $this->order->billingAddress->get()->getID() == $this->order->shippingAddress->get()->getID()) {
         $this->order->billingAddress->set(clone $this->order->billingAddress->get());
         $this->order->billingAddress->get()->save();
     }
     if ($this->request->get('sameAsShipping')) {
         $this->order->billingAddress->set(clone $this->order->shippingAddress->get());
         $this->order->billingAddress->get()->save();
         if (!$this->user->isAnonymous()) {
             $this->order->save();
         }
     } else {
         try {
             $res = parent::doSelectAddress();
             if ($res instanceof ActionRedirectResponse && $res->getActionName() == 'selectAddress') {
                 $params = $res->getParamList();
                 if (empty($params['step']) || 'shipping' != $params['step']) {
                     $errorResponse = parent::selectAddress();
                     $errorList = $errorResponse->get('form')->getValidator()->getErrorList();
                     if ($errorList) {
                         return new JSONResponse(array('errorList' => $errorList));
                     }
                 }
             }
         } catch (SQLException $e) {
             //throw $e;
             $this->order->billingAddressID->resetModifiedStatus();
             SessionOrder::save($this->order);
         }
     }
     if ($this->user->isAnonymous()) {
         $this->user->defaultBillingAddress->get()->userAddress->set($this->order->billingAddress->get());
         $this->saveAnonUser($this->user);
     }
     // attempt to pre-select a shipping method
     $this->shippingMethods();
     return $this->getUpdateResponse('shippingMethods');
 }
 public function doSelectShippingAddress()
 {
     $sameAddress = $this->config->get('REQUIRE_SAME_ADDRESS');
     $this->config->setRuntime('REQUIRE_SAME_ADDRESS', false);
     $this->order->loadAll();
     $this->request->set('step', 'shipping');
     $this->initAnonUser();
     if ($this->user->isAnonymous()) {
         try {
             $billing = $this->user->defaultBillingAddress->get();
             if ($err = $this->setAddress('shipping')) {
                 return $err;
             }
         } catch (Exception $e) {
             $this->user->defaultBillingAddress->set($billing);
             $this->user->defaultShippingAddress->set($this->lastAddress);
             if ($this->user->defaultShippingAddress->get()) {
                 $this->order->shippingAddress->set($this->user->defaultShippingAddress->get()->userAddress->get());
             }
             if ($this->order->shippingAddress->get() && $this->order->shippingAddress->get()->getID() == $this->order->billingAddress->get()->getID()) {
                 $shipping = clone $this->user->defaultBillingAddress->get()->userAddress->get();
                 if (!$this->user->defaultShippingAddress->get()) {
                     $this->user->defaultShippingAddress->set(ShippingAddress::getNewInstance($this->user, $shipping));
                 }
                 $this->user->defaultShippingAddress->get()->userAddress->set($shipping);
             }
             $this->saveAnonUser($this->user);
             $this->order->shippingAddress->resetModifiedStatus();
             SessionOrder::save($this->order);
         }
     } else {
         if ($err = $this->setAddress('shipping')) {
             return $err;
         }
         // UserAddress::toString() uses old data otherwise
         if ($this->order->shippingAddress->get()) {
             $this->order->shippingAddress->get()->resetArrayData();
             if ($sameAddress) {
                 $this->order->billingAddress->set($this->order->shippingAddress->get());
                 $this->order->save();
             } else {
                 if ($this->request->get('sameAsShipping') && (!$this->order->billingAddress->get() && $this->order->shippingAddress->get() && $this->order->isShippingRequired() || $this->order->billingAddress->get() && $this->order->shippingAddress->get() && $this->order->billingAddress->get()->toString() != $this->order->shippingAddress->get()->toString())) {
                     $this->order->billingAddress->set(clone $this->order->shippingAddress->get());
                     $this->order->billingAddress->get()->save();
                     $this->order->save();
                 }
             }
         }
     }
     // attempt to pre-select a shipping method
     ActiveRecord::clearPool();
     $this->config->resetRuntime('DELIVERY_TAX_CLASS');
     $this->order = CustomerOrder::getInstanceById($this->order->getID(), true);
     if (isset($anonOrder)) {
         $this->order->shippingAddress->set($anonOrder->shippingAddress->get());
         $this->order->billingAddress->set($anonOrder->billingAddress->get());
     }
     // @todo: needs to be called twice for the auto-selection to get saved
     $this->init();
     $this->shippingMethods();
     $this->config->setRuntime('REQUIRE_SAME_ADDRESS', $sameAddress);
     return new ActionRedirectResponse('onePageCheckout', 'update');
     //return $this->getUpdateResponse('shippingMethods', 'shippingAddress', 'billingAddress');
 }
Example #8
0
 protected function finalizeOrder($options = array())
 {
     if (!count($this->order->getShipments())) {
         throw new ApplicationException('No shipments in order');
     }
     $user = $this->order->user->get();
     $user->load();
     $newOrder = $this->order->finalize($options);
     $orderArray = $this->order->toArray(array('payments' => true));
     // send order confirmation email
     if ($this->config->get('EMAIL_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setUser($user);
         $email->setTemplate('order.new');
         $email->set('order', $orderArray);
         $email->send();
     }
     // notify store admin
     if ($this->config->get('NOTIFY_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setTo($this->config->get('NOTIFICATION_EMAIL'), $this->config->get('STORE_NAME'));
         $email->setTemplate('notify.order');
         $email->set('order', $orderArray);
         $email->set('user', $user->toArray());
         $email->send();
     }
     $this->session->set('completedOrderID', $this->order->getID());
     if ($newOrder instanceof CustomerOrder) {
         SessionOrder::save($newOrder);
     } else {
         SessionOrder::destroy();
     }
     return new ActionRedirectResponse('checkout', 'completed');
 }