Torann / laravel-currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
http://lyften.com/projects/laravel-currency
BSD 2-Clause "Simplified" License
392 stars 137 forks source link

please update the currency middleware , it's full of bugs , i have fixed for u #57

Closed uusa35 closed 7 years ago

brobyns commented 7 years ago

Nice fixes but there is still one bug in 'setUserCurrency' it should be like this:

private function setUserCurrency($currency, $request)
    {
        $currency = strtoupper($currency);

        if ($request->has('currency')) {
            $request->session()->put('currency', $request->get('currency'));

        } else {
            $request->getSession()->put(['currency' => $currency]);

        }
        currency()->setUserCurrency($currency);
    }
Torann commented 7 years ago

But that's not doing what the method is set to do, it's suppose to set the user's currency. All the stuff you're trying to add to the setUserCurrency method is already in the getUserCurrency.

The flow works like this. The request comes into the handle method, where we get the currency using getUserCurrency. In the getUserCurrency we check the request for a valid currency parameter and if one is not found we then check the session for a previously set valid currency. And if neither the request nor the session have valid a currency, we return null. Back in the handle method if we get null we then pull the system default.

So as you can see we already check the request and the session, so there is no need to check that again in the setUserCurrency method. This should be done before using the setUserCurrency method.

arhakim commented 4 years ago

Hi @Torann Where did you set the session currency and how did you set the status currency to active (database)? I tried to call the URL with ?currency=idr but the currency still use the default currency which is USD