/** * GET /products[/:id] * @return \Nohex\Eix\Core\Responses\Http\Html */ public function httpGetForHtml() { $response = new HtmlResponse($this->getRequest()); $id = $this->getRequest()->getParameter('id'); $groupId = $this->getRequest()->getParameter('groupId'); switch ($id) { case NULL: if ($groupId) { $group = ProductGroups::getInstance()->findEntity($groupId); $response->setData('group', $group->name); } $productList = $this->getProductList($groupId); if (empty($productList)) { $response->setTemplateId('products/empty'); } else { $response->setTemplateId('products/index'); $response->setData('products', $productList); } $response->appendToTitle(_('Productes')); break; default: $response->setTemplateId('products/view'); $product = $this->getForDisplay($id); if ($product['enabled']) { $response->setData('product', $product); $response->appendToTitle(_($product['name'])); } else { throw new NotFoundException('Product not found'); } break; } return $response; }
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; }