/** * Save joined row * * @param ProductJoinedRow $productJoinedRow * @return void */ public function saveProductJoinedRow(ProductJoinedRow $productJoinedRow) { // Save Product $product = new Product(); $productTable = new ProductTable($this->adapter); $product->exchangeArray($productTable->filterByColumns($productJoinedRow->toArray())); $productTable->saveProduct($product); if ($productId = $productTable->getLastInsertValue()) { // Add product $productJoinedRow->product_id = $productId; } // Save ProductDescription $productDescription = new ProductDescription(); $productDescriptionTable = new ProductDescriptionTable($this->adapter); $productDescription->exchangeArray($productDescriptionTable->filterByColumns($productJoinedRow->toArray())); $productDescriptionTable->saveProductDescription($productDescription); }
public function addAction() { $form = new ProductForm(); $request = $this->getRequest(); if ($request->isPost()) { $product = new Product(); $form->setInputFilter($product->getInputFilter()); $form->setData($request->post()); if ($form->isValid()) { $formData = $form->getData(); $product->populate(${$formData}); $this->getProductTable()->saveProduct($product); return $this->redirect()->toRoute('catalog-product', array('action' => 'view')); } } return array('form' => $form); }
public function getAction($id) { if ($id <= 0) { throw new Exception('Wrong id passed', 500); } /** * @var $entity Product|boolean */ $entity = Product::findFirst($id); if (!$entity) { throw new Exception('Product not found', 404); } return array('success' => true, 'result' => array('id' => $entity->id, 'title' => $entity->title)); }
public function indexAction() { $this->view->setLayout('catalog'); $this->view->categories = Category::find(); $this->view->products = Product::find(); }
/** * Update a product * * @param Product $product * @return int */ public function updateProduct(Product $product) { return $this->update($product->toArray(), array('product_id' => $product->product_id)); }
public function indexAction($productId) { $this->view->setLayout('index'); $this->view->product = Product::findFirst(); }