/** * Load the list scoreboard data * * @return void */ public function loadScoreboard() { $products = Product::isEnabled()->count(); $discounted = Product::discounted()->isEnabled()->count(); $meter = $products > 0 ? round($discounted / $products * 100) : 0; $this->vars['scoreboard'] = ['products' => $products, 'discounted' => $discounted, 'meter' => $meter]; }
/** * 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)]; }
public function test_discounted_scope() { $foo = Factory::create(new Product()); $bar = Factory::create(new Product()); Factory::create(new Price(), ['product_id' => $bar->id, 'discount_id' => 1, 'price' => $bar->base_price - 1]); $discounted = Product::discounted()->get(); $this->assertEquals(1, $discounted->count()); $this->assertEquals($bar->id, $discounted->first()->id); $this->assertTrue($discounted->first()->isDiscounted()); }