Example #1
0
 /**
  * Creates a product.
  *
  * @return void
  */
 public function post_index()
 {
     $validator = \Validation_Product::create();
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $product = \Service_Product::create($data['name'], \Seller::active(), $data);
     if (!$product) {
         throw new HttpServerErrorException();
     }
     $this->response($product);
 }
Example #2
0
 /**
  * POST Create action.
  *
  * @return void
  */
 public function post_create()
 {
     $this->get_create();
     $validator = Validation_Product::create();
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $data = $validator->validated();
     if (!Service_Product::create($data['name'], Seller::active(), $data)) {
         Session::set_alert('error', 'There was an error adding the product.');
         return;
     }
     Session::set_alert('success', 'The product has been added.');
     Response::redirect('products');
 }
Example #3
0
 /**
  * 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');
 }