bazar icon indicating copy to clipboard operation
bazar copied to clipboard

Price formatting problem

Open bobitza opened this issue 3 years ago • 0 comments

  • Bazar Version: last
  • Laravel Version: 8.2
  • PHP Version: 7.4

Description:

You have a function in src/Casts/Price.php, this function format price and give from config ex 'eur' => 'EUR' or i have 'ron' => 'Lei' But give me RON not Lei string

    public function format(?string $key = null): ?string
    {
        $currency = $key ? explode('.', $key, 2)[0] : Bazar::getCurrency();
        $price = Arr::get(
            $this->toArray(), $key ?: "{$currency}.default"
        );
        return $price ? Str::currency($price, $currency) : null;
    }

So need to fix with this

public function format(?string $key = null): ?string
 {
     
     $currency = $key ? explode('.', $key, 2)[0] : Bazar::getCurrency();
     //--
     $price = Arr::get(
         $this->toArray(), $key ?: "{$currency}.default"
     );
     //--
     return $price ? Str::currency($price, array_search($currency, Bazar::getCurrencies())) : null;
 }

Steps To Reproduce:

bobitza avatar Feb 16 '22 17:02 bobitza