conedevelopment / bazar

Bazar is an e-commerce package for Laravel applications.
https://root.conedevelopment.com
MIT License
421 stars 56 forks source link

Price formatting problem #188

Closed bobitza closed 11 months ago

bobitza commented 2 years ago

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: