Пример #1
0
 private function createOrder(PaymentForm $form)
 {
     $values = $form->getValues();
     $this->orderService->createFromCart($this->currentCartService->getCurrentCart(), PaymentType::createFromValue($values->paymentType));
     $this->currentCartService->resetCurrentCart();
     $this->redirect(':Front:Order:Order:');
 }
Пример #2
0
 protected function startup()
 {
     parent::startup();
     if (!$this->currentCartService->getCurrentCart()->hasItems()) {
         $this->flashMessage('Yout cart is empty.');
         $this->redirect(':Front:Home:Homepage:');
     }
 }
Пример #3
0
 public function beforeRender()
 {
     parent::beforeRender();
     $this->template->categories = $this->categoryService->getRoot();
     $this->template->currentCategory = $this->currentCategory;
     $this->template->cart = $this->currentCartService->getCurrentCart();
     $this->template->user = $this->user;
 }
Пример #4
0
 private function updateAddress(AddressForm $form)
 {
     $values = $form->getValues();
     $this->currentCartService->getCurrentCart()->setAddress($values->address->name, $values->address->street, $values->address->city, $values->address->zip);
     if (!$form->hasErrors()) {
         $this->currentCartService->saveCurrentCart();
         $this->redirect(':Front:Order:Payment:');
     }
 }
Пример #5
0
 private function updateShipment(ShipmentForm $form)
 {
     $values = $form->getValues();
     $shipmentOption = $form->getChosenShipment();
     if (isset($values->address)) {
         $this->cartService->createShipmentForCart($this->currentCartService->getCurrentCart(), $shipmentOption, $values->address->name, $values->address->street, $values->address->city, $values->address->zip);
     } else {
         $this->cartService->createShipmentForCart($this->currentCartService->getCurrentCart(), $shipmentOption);
     }
     $this->currentCartService->saveCurrentCart();
     $this->redirect(':Front:Order:Payment:');
 }
Пример #6
0
 private function addProductToCart(BuyForm $form)
 {
     $values = $form->getValues();
     $item = new CartItem($this->product, $values->amount);
     $this->currentCartService->getCurrentCart()->addItem($item);
     if (!$form->hasErrors()) {
         $this->currentCartService->saveCurrentCart();
         if ($item->getAmount() > 1) {
             $this->flashMessage(sprintf('%dx %s was added to cart.', $item->getAmount(), $this->product->getName()));
         } else {
             $this->flashMessage(sprintf('%s was added to cart.', $this->product->getName()));
         }
         $this->redirect('this');
     }
 }
Пример #7
0
 private function recalculateCart(CartForm $form)
 {
     $removeItemId = $form->getRemoveItemId();
     if ($removeItemId !== null) {
         $this->cartService->removeItemFromCart($this->cartService->getItemById($removeItemId));
     } else {
         $values = $form->getValues();
         foreach ($values->amount as $itemId => $amount) {
             $item = $this->cartService->getItemById($itemId);
             $item->setAmount($amount);
             $this->currentCartService->saveCurrentCart();
         }
     }
     $this->flashMessage('Cart has been recalculated.');
     $this->redirect('this');
 }
Пример #8
0
 private function addEventListeners($permanentLoginExpiration)
 {
     $this->onValidate[] = function () {
         $values = $this->getValues();
         try {
             $this->user->login($values->email, $values->password);
             $this->currentCartService->consolidateCurrentCartWithCurrentUser();
         } catch (AuthenticationException $e) {
             $this->addError('Invalid credentials.');
         }
     };
     $this->onSuccess[] = function () use($permanentLoginExpiration) {
         $values = $this->getValues();
         if ($values->permanent) {
             $this->user->setExpiration($permanentLoginExpiration, false);
         } else {
             $this->user->setExpiration(0, true);
         }
     };
 }
Пример #9
0
 private function registerUser(RegistrationForm $form)
 {
     $values = $form->getValues();
     $user = new User($values->email, $values->password);
     $user->setName($values->address->name);
     $user->setStreet($values->address->street);
     $user->setCity($values->address->city);
     $user->setZip($values->address->zip);
     try {
         if (!$form->hasErrors()) {
             $this->userService->create($user);
             $this->flashMessage('Account has been created.');
             $this->user->login($user->getEmail(), $values->password);
             $this->currentCartService->consolidateCurrentCartWithCurrentUser();
             $this->restoreRequest($this->backlink);
             $this->redirect(':Front:Home:Homepage:');
         }
     } catch (EntityDuplicateException $e) {
         $form->addError(sprintf('User with e-mail %s already exists.', $user->getEmail()));
     }
 }