/**
  * 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)];
 }
 /**
  * Load a page of products for a given category
  *
  * @param  \Bedard\Shop\Models\Category         $category
  * @param  integer                              $page
  * @param  boolean                              $load_thumbnails
  * @param  boolean                              $load_gallery
  * @param  boolean                              $load_inventories
  * @return \October\Rain\Database\Collection
  */
 public function getProducts(Category $category, $page = 1, $load_thumbnails = false, $load_gallery = false, $load_inventories = false)
 {
     $query = Product::joinPrice();
     if ($load_inventories) {
         $query->joinInventory();
     }
     if ($load_thumbnails) {
         $query->with('thumbnails');
     }
     if ($load_gallery) {
         $query->with('images');
     }
     return $query->isEnabled()->inCategory($category)->onPage($category, $page)->get();
 }
 public function test_join_price_scope()
 {
     $product = Factory::create(new Product(), ['base_price' => 20]);
     $this->assertEquals(20, Product::joinPrice()->find($product->id)->price);
     $expired = Factory::create(new Price(), ['product_id' => $product->id, 'discount_id' => 1, 'price' => 5, 'start_at' => Carbon::now()->subDays(2), 'end_at' => Carbon::yesterday()]);
     $expired = Factory::create(new Price(), ['product_id' => $product->id, 'discount_id' => 2, 'price' => 10, 'start_at' => Carbon::now()]);
     $expired = Factory::create(new Price(), ['product_id' => $product->id, 'discount_id' => 3, 'price' => 15, 'start_at' => Carbon::tomorrow()]);
     $this->assertEquals(10, Product::joinPrice()->find($product->id)->price);
 }