Пример #1
0
 private function getAuthenticationResponse($orderId)
 {
     $validationErrors = array();
     $order = null;
     try {
         $order = $this->getEntity($orderId);
         $securityCode = $this->getRequest()->getParameter('security_code');
         // Check that a security code is presented.
         if (empty($securityCode)) {
             $validationErrors[] = _('The security code is missing.');
         } else {
             // Check that the security code matches the expected one.
             if ($order->securityCode != $securityCode) {
                 $validationErrors[] = _('The security code is incorrect.');
             }
         }
     } catch (NotFoundException $exception) {
         // Same error for wrong codes and non-existing orders, to avoid
         // enumeration.
         $validationErrors[] = _('The security code is incorrect.');
     }
     $response = NULL;
     // If the validation status is empty, everything looks ok.
     if (empty($validationErrors)) {
         // If the order is new, this step just validated the customer's
         // e-mail address.
         if ($order->getStatus() == Order::STATUS_NEW) {
             // Set the status and notify the vendor.
             $order->setStatus(Order::STATUS_CONFIRMED_BY_CUSTOMER, true);
             // Store the order with the new status.
             $order->store();
             // Display the order's new status.
         }
         // Redirect to the order view page with the authentication code.
         $response = new Redirection($this->getRequest());
         $response->setNextUrl(sprintf('/comandes/%s/%s', $order->getId(), $order->getAuthenticationCode()));
     } else {
         // Validation failed.
         $response = new HtmlResponse($this->getRequest());
         $response->addErrorMessage(array('validation' => array('security_code' => $validationErrors)));
         $response->setTemplateId('orders/view');
         $response->setData('order', array('id' => $orderId));
     }
     return $response;
 }
Пример #2
0
 /**
  * Empties the basket.
  */
 private function getBasketClearedResponse()
 {
     $response = NULL;
     try {
         // Remove all products from the current customer's basket.
         Customers::getCurrent()->getBasket()->clear();
         $response = new RedirectionResponse($this->getRequest());
         $response->setNextUrl('/cistella');
     } catch (\Exception $exception) {
         $response = $this->getViewPageResponse();
         $customerId = Customers::getCurrent()->getId();
         Logger::get()->error("Failed to clear customer {$customerId}'s basket.");
         $response->addErrorMessage(_('The basket could not be cleared.'));
     }
     return $response;
 }