/** * Creates a product option fee. * * @param int $option_id Product option ID. * * @return void */ public function post_index($option_id = null) { $option = $this->get_option($option_id); $validator = \Validation_Product_Option_Fee::create(); if (!$validator->run()) { throw new HttpBadRequestException($validator->errors()); } $data = $validator->validated(); $fee = \Service_Product_Option_Fee::create($data['name'], $data['interval'], $data['interval_unit'], $data['interval_price'], $option); if (!$fee) { throw new HttpServerErrorException(); } $this->response($fee); }
/** * POST Create action. * * @param int $option_id Product option ID the new fee should belong to. * * @return void */ public function post_create($option_id = null) { $this->get_create($option_id); $validator = Validation_Product_Option_Fee::create(); if (!$validator->run()) { Session::set_alert('error', __('form.error')); $this->view->errors = $validator->error(); return; } $option = $this->get_option($option_id); $data = $validator->validated(); if (!Service_Product_Option_Fee::create($data['name'], $data['interval'], $data['interval_unit'], $data['interval_price'], $option, $data)) { Session::set_alert('error', 'There was an error adding the product option fee.'); return; } Session::set_alert('success', 'The product option fee has been added.'); Response::redirect($option->link('fees')); }
/** * 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'); }