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