/** * Attempts to get a product from a given ID. * * @param int $id Product ID. * * @return \Model_Product */ protected function get_product($id) { if (!$id) { throw new HttpNotFoundException(); } $product = \Service_Product::find_one($id); if (!$product || $product->seller != \Seller::active()) { throw new HttpNotFoundException(); } return $product; }
/** * 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'); }
/** * Deletes a product. * * @param int $id Product ID. * * @return void */ public function delete_index($id = null) { if (!$id) { throw new HttpNotFoundException(); } $product = \Service_Product::find_one($id, \Seller::active()); if (!$product || $product->seller != \Seller::active()) { throw new HttpNotFoundException(); } $deleted = \Service_Product::delete($product); if (!$deleted) { throw new HttpServerErrorException(); } }