示例#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');
 }
示例#2
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');
     }
 }
 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');
 }
示例#4
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');
 }
示例#5
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');
 }