public function test_getting_formatted_prices() { CurrencySettings::set('symbol', '$'); CurrencySettings::set('decimal_character', '.'); CurrencySettings::set('thousands_seperator', ','); $product = Factory::create(new Product(), ['base_price' => 1234.56]); Factory::create(new Price(), ['product_id' => $product->id, 'discount_id' => 1, 'price' => 78.90000000000001]); $this->assertEquals('$1,234.56', $product->getFormattedBasePrice()); $this->assertEquals('$78.90', $product->getFormattedPrice()); }
public function test_getting_the_formatted_amount() { CurrencySettings::set('symbol', '$'); CurrencySettings::set('decimal_character', '.'); CurrencySettings::set('thousands_seperator', ','); $discount1 = Factory::create(new Discount(), ['amount_percentage' => 50, 'is_percentage' => true]); $discount2 = Factory::create(new Discount(), ['amount_exact' => 1.23, 'is_percentage' => false]); $this->assertEquals('50%', $discount1->getFormattedAmount()); $this->assertEquals('$1.23', $discount2->getFormattedAmount()); }
/** * 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)]; }
/** * Returns the formatted discount amount * * @return string */ public function getFormattedAmount() { return $this->is_percentage ? $this->amount_percentage . '%' : CurrencySettings::format($this->amount_exact); }
/** * Format the filter into a human-readable string * * @return string */ public function getFilterStringAttribute() { if ($this->left === 'created_at') { $string = $this->operator === '<' ? 'bedard.shop::lang.filter.string_created_more_than' : 'bedard.shop::lang.filter.string_created_less_than'; $value = $this->right; } elseif ($this->left === 'price' && $this->right !== 'base_price') { $string = $this->operator === '<' ? 'bedard.shop::lang.filter.string_price_less_than' : 'bedard.shop::lang.filter.string_price_greater_than'; $value = CurrencySettings::format($this->right); } else { $string = 'bedard.shop::lang.filter.string_discounted'; } $days = is_numeric($this->right) && $this->right == 1 ? Lang::get('bedard.shop::lang.filter.string_days_singular') : Lang::get('bedard.shop::lang.filter.string_days_plural'); return Lang::get($string, compact('value', 'days')); }
/** * Register twig extensions * * @return array */ public function registerMarkupTags() { return ['filters' => ['currency' => function ($value) { return CurrencySettings::format($value); }]]; }
/** * Returns the formatted price * * @return string */ public function getFormattedPrice($value = null) { return CurrencySettings::format($this->price); }