public function showAction() { $auth = new AuthenticationService(); //if you guest - go to product list if (!$auth->getIdentity()) { return $this->redirect()->toRoute('store'); } //initialization $form = new OrderForm(); $status = $message = ''; $id = $this->params()->fromRoute('id', 0); //show form return new ViewModel(array('product' => Product::getProduct($id), 'form' => $form, 'id' => $id)); }
public static function getUpdatedProducts() { $list = ''; if (isset($_COOKIE['basket'])) { $products = $_COOKIE['basket']; ksort($products); foreach ($products as $product) { $product = json_decode($product); $list .= '<li><span name="qua">' . $product->quantity . 'x</span> ' . '<span name="product">' . Product::getProduct($product->id)['product_name'] . '</span>' . '<button onclick="deleteProductFromBasket(' . $product->id . ', 1)">' . '<img src="/img/delete.png" alt="X">' . '</button>' . '</li>'; } } else { $list = '<li>Корзина порожня</li>'; } return $list; }
public function editAction() { //initialization $form = new ProductAddForm(); $status = $message = ''; $id = (int) $this->params()->fromRoute('id', 0); $product = new Product(); $db = new DbFunctions(); //get product data $data = Product::getProduct($id); // $data = $db->getEntity('product', $id); //if find 0 go product list if (empty($data)) { $status = 'error'; $message = 'Продукт не знайдено'; $this->flashMessenger()->setNamespace($status)->addMessage($message); return $this->redirect()->toRoute('admin/product'); } $product->dbToProduct($data); $form->bind($product); //check request if(post) save else show filled form on view $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { //save $product->update($id); $status = 'success'; $message = 'Зміни збережено'; } else { $status = 'error'; $message = 'Помилка параметрів'; foreach ($form->getInputFilter()->getInvalidInput() as $errors) { foreach ($errors->getMessages() as $error) { $message .= ' ' . $error; } } } } else { return array('form' => $form, 'id' => $id); } //make message if ($message) { $this->flashMessenger()->setNamespace($status)->addMessage($message); } //go to product list return $this->redirect()->toRoute(); }
public function productsAction() { //initialization $message = $status = ''; $version = $this->params()->fromRoute('v', false); if (in_array($version, Methods::getSupportedVersion())) { $param = $this->params()->fromRoute('param', false); $resource = $this->params()->fromRoute('resource', false); switch (Methods::getMethod()) { case 'GET': $status = 'GET'; $message = Product::getProduct($param); break; case 'POST': $status = 'POST'; $message = 'POST'; break; case 'PUT': $status = 'PUT'; $message = 'PUT'; break; case 'DELETE': $status = 'DELETE'; $message = 'DELETE'; break; } } else { $status = 'ERROR'; $message = 'Not supported Version API'; } //make message for JS if ($message) { echo json_encode(array('method' => $status, 'message' => $message)); } return true; }