/** * POST Edit action. * * @param int $id Product ID. * * @return void */ public function post_edit($id = null) { $this->get_edit($id); $validator = Validation_Product::update(); if (!$validator->run()) { Session::set_alert('error', __('form.error')); $this->view->errors = $validator->error(); return; } $product = $this->get_product($id); $data = $validator->validated(); if (!Service_Product::update($product, $data)) { Session::set_alert('error', 'There was an error updating the product.'); return; } Session::set_alert('success', 'The product has been updated.'); Response::redirect($product->link('edit')); }
/** * Updates a product. * * @param int $id Product ID. * * @return void */ public function put_index($id = null) { if (!$id) { throw new HttpNotFoundException(); } $product = \Service_Product::find_one($id); if (!$product || $product->seller != \Seller::active()) { throw new HttpNotFoundException(); } $validator = \Validation_Product::update(); if (!$validator->run(\Input::put())) { throw new HttpBadRequestException($validator->errors()); } $data = $validator->validated(); $product = \Service_Product::update($product, $data); if (!$product) { throw new HttpServerErrorException(); } $this->response($product); }