Money middleware added currency_code and document issue fixed..
This commit is contained in:
parent
8651bc6c9b
commit
d46bff3c2d
@ -23,6 +23,12 @@ class Money
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currency_code = setting('default.currency');
|
||||||
|
|
||||||
|
if ($request->has('currency_code')) {
|
||||||
|
$currency_code = $request->get('currency_code');
|
||||||
|
}
|
||||||
|
|
||||||
$parameters = [
|
$parameters = [
|
||||||
'amount',
|
'amount',
|
||||||
'sale_price',
|
'sale_price',
|
||||||
@ -41,7 +47,7 @@ class Money
|
|||||||
$money_format = Str::replaceFirst(',', '.', $money_format);
|
$money_format = Str::replaceFirst(',', '.', $money_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = $this->getAmount($money_format);
|
$amount = $this->getAmount($money_format, $currency_code);
|
||||||
|
|
||||||
$request->request->set($parameter, $amount);
|
$request->request->set($parameter, $amount);
|
||||||
}
|
}
|
||||||
@ -56,7 +62,11 @@ class Money
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = $this->getAmount($item['price']);
|
$amount = $item['price'];
|
||||||
|
|
||||||
|
if (strpos($item['price'], config('money.' . $currency_code . '.symbol')) !== false) {
|
||||||
|
$amount = $this->getAmount($item['price'], $currency_code);
|
||||||
|
}
|
||||||
|
|
||||||
$items[$key]['price'] = $amount;
|
$items[$key]['price'] = $amount;
|
||||||
}
|
}
|
||||||
@ -68,10 +78,14 @@ class Money
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAmount($money_format)
|
protected function getAmount($money_format, $currency_code)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$amount = money($money_format)->getAmount();
|
if (config('money.' . $currency_code . '.decimal_mark') !== '.') {
|
||||||
|
$money_format = Str::replaceFirst('.', config('money.' . $currency_code . '.decimal_mark'), $money_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = money($money_format, $currency_code)->getAmount();
|
||||||
} catch (InvalidArgumentException | OutOfBoundsException | UnexpectedValueException $e) {
|
} catch (InvalidArgumentException | OutOfBoundsException | UnexpectedValueException $e) {
|
||||||
logger($e->getMessage());
|
logger($e->getMessage());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user