public function renderProduct() { if (AppUserRolesConfig::hasAddEditDeletePriviligies()) { FormViewHelper::init(); FormViewHelper::setAttribute('class', 'productForm'); FormViewHelper::setMethod("post"); FormViewHelper::setAction(\EShop\Config\RouteConfig::getBasePath() . 'products/edit'); FormViewHelper::initTextField()->setName('productName')->setValue($this->productOldInformation->getProductName())->setAttribute('class', 'form-group')->create(); FormViewHelper::initHiddenField()->setName('productId')->setValue($this->productOldInformation->getProductId())->setAttribute('class', 'form-group')->create(); FormViewHelper::initTextField()->setName('quantity')->setValue($this->productOldInformation->getQuantity())->create(); $select = FormViewHelper::initSelect(); $select->setAttribute('class', 'form-group'); $select->setName('categoryId'); foreach ($this->categories as $category) { if ($category->getId() == $this->productOldInformation->getCategoryId()) { $select->addOption($category->getId(), $category->getName(), true); } else { $select->addOption($category->getId(), $category->getName()); } } $select->create(); FormViewHelper::initSubmitButton()->setValue('Edit')->setAttribute('class', 'btn-primary btn-lg')->create()->render(); } }
public function update(EditProductBindingModel $model) { $productId = $model->getProductId(); $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array('name' => $model->getProductName(), 'category_id' => $model->getCategoryId(), 'quantity' => $model->getQuantity()), $productId); return $isUpdated; }