/** * Creates a product option. * * @param int $product_id Product ID. * * @return void */ public function post_index($product_id = null) { $product = $this->get_product($product_id); $validator = \Validation_Product_Option::create(); if (!$validator->run()) { throw new HttpBadRequestException($validator->errors()); } $data = $validator->validated(); $option = \Service_Product_Option::create($data['name'], $product, $data); if (!$option) { throw new HttpServerErrorException(); } $this->response($option); }
/** * POST Create action. * * @param int $product_id Product ID the new option should belong to. * * @return void */ public function post_create($product_id = null) { $this->get_create($product_id); $validator = Validation_Product_Option::create(); if (!$validator->run()) { Session::set_alert('error', __('form.error')); $this->view->errors = $validator->error(); return; } $product = $this->get_product($product_id); $data = $validator->validated(); if (!Service_Product_Option::create($data['name'], $product, Arr::filter_recursive($data))) { Session::set_alert('error', 'There was an error adding the product option.'); return; } Session::set_alert('success', 'The product option has been added.'); Response::redirect($product->link('options')); }