Exemplo n.º 1
0
 /**
  * Load the list scoreboard data
  *
  * @return void
  */
 public function loadScoreboard()
 {
     $total = Product::count();
     $enabled = Product::isEnabled()->count();
     $inStock = Product::inStock()->isEnabled()->count();
     $outOfStock = Product::outOfStock()->isEnabled()->count();
     $discounted = Product::discounted()->isEnabled()->count();
     $averagePrice = Product::joinPrice()->isEnabled()->avg('price');
     $disabled = $total - $enabled;
     $this->vars['scoreboard'] = ['total' => $total, 'enabled' => $enabled, 'disabled' => $disabled, 'inStock' => $inStock, 'outOfStock' => $outOfStock, 'averagePrice' => CurrencySettings::format($averagePrice)];
 }
Exemplo n.º 2
0
 public function test_in_stock_and_out_of_stock_scopes()
 {
     $foo = Factory::create(new Product());
     $bar = Factory::create(new Product());
     Factory::create(new Inventory(), ['product_id' => $foo->id, 'quantity' => 1]);
     Factory::create(new Inventory(), ['product_id' => $bar->id, 'quantity' => 0]);
     $in_stock = Product::inStock()->get();
     $out_of_stock = Product::outOfStock()->get();
     $this->assertEquals(1, $in_stock->count());
     $this->assertEquals(1, $out_of_stock->count());
     $this->assertEquals($foo->id, $in_stock->first()->id);
     $this->assertEquals($bar->id, $out_of_stock->first()->id);
 }