/** * 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')); }
/** * Generates products. * * @return void */ protected static function products() { foreach (self::$sellers as $seller) { $product = \Service_Product::create('Product Line ' . \Str::upper(\Str::random('alpha', 1)), $seller); if ($product) { for ($i = 1; $i <= 3; $i++) { $option = \Service_Product_Option::create('Product ' . \Str::upper(\Str::random('alpha', 1)), $product); if ($option) { self::$product_options[$seller->id][] = $option; \Service_Product_Option_Fee::create('Subscription', 1, 'month', mt_rand(5, 15), $option); } } } } \Cli::write('Product Simulation Complete', 'green'); }