Comments (13)
Awesome! Hopefully I can start working on a PR for it this weekend 👍
from laravel-shopr.
Yea, will definitely do that, will report back once I get to it 👍
I like the API!
from laravel-shopr.
@Reached Thanks for taking the time to test it out! It really helps. I just have to solve a few problems that came up when running the test suite in Travis, then I'll merge this 👍
from laravel-shopr.
@Reached Ah thanks so much, that makes me super happy to hear! ❤️
I think this is a great idea, and I've been meaning to make the money formatting a bit more customizable. I'd love to give as much flexibility as possible without bloating the config file though.
What about providing your own MoneyFormatter-class? Something like this:
'currency' => 'DKK',
// The default formatter which you could switch to your own.
'money_formatter' => Happypixels\Shopr\Money\Formatter::class,
And then in the formatter class we could make it super easy to provide whatever details you want and just skip the ones you don't want to modify:
class CustomFormatter extends Happypixels\Shopr\Money\Formatter
{
// Define the options you want to change. Either like this, or with single line methods. Not sure which approach is the best.
public static $symbol = 'kr';
public static $symbolBefore = '$'; // This would be weird, I know. But possible. ('$213kr')
public static $decimalMark = ',';
// We could even allow formatting the amount without any restrictions.
// Defining this method on your own formatter would be completely optional, your other settings
// would still be used when formatting amounts.
public function format($amount)
{
if($amount > 1000){
return 'Too much money, can\'t handle it.';
}
return $amount.' kr';
}
}
This would create a setup similar to the Nova-resources. What do you think? Would this cover your needs and feel manageable?
from laravel-shopr.
I think that is a great solution, extendable and doesn't bloat the config as you pointed out 👌 !
from laravel-shopr.
Awesome! Let me know if I can help! :)
from laravel-shopr.
@Reached Would you be able to test this out before I merge it? I believe I've tested it pretty well but always good to have another pair of eyes on it.
Using the feature/custom-money-formatter branch, you can now add your own formatter and enable it using the 'money_formatter'
-key in the config as we said.
You can either customize 5 different options like this:
<?php
namespace App;
use Happypixels\Shopr\Money\Formatter;
class CustomFormatter extends Formatter
{
public $symbol = ' kr';
public $symbolBefore = null; // You don't even need this in your class if you don't want to modify it.
public $thousandSeparator = '.';
public $decimalCount = 2;
public $decimalSeparator = ',';
}
Or format the amount freely using the format
-method:
<?php
namespace App;
use Happypixels\Shopr\Money\Formatter;
class CustomFormatter extends Formatter
{
public function format($amount)
{
return $amount.' kr';
}
}
Let me know if you have any questions!
from laravel-shopr.
Works great when I just return the amount from the format function, but when using the public properties it seems that setting the decimal count to 0 does not remove the decimals, however setting it to 1 does indeed remove one decimal.
Also it seems that there is no obvious way to move the symbol to after the amount without using the public function format($amount) it seems? :)
from laravel-shopr.
Ah, I'll take a look on the decimal issue.
Well, I believe the NumberFormatter class automatically puts the symbol on the "correct side" of the amount, depending on your currency code and app locale. Maybe we should add $symbolAfter
, and force that to be after like we do with $symbolBefore
. And if you want to let PHP decide which side the symbol should be on, you could just use the $symbol
property. Would that make sense?
Thanks for your report!
from laravel-shopr.
Actually, how about just a $symbol
and a $symbolPosition
? Feels like that would make the API a bit less confusing.
from laravel-shopr.
Ok @Reached, I fixed the decimal issue, removed $symbolBefore
and replaced it with $symbolPosition
. Set this to either 'before' or 'after' to modify it. If left blank, PHP will auto-position the symbol depending on your currency code and app locale. Let me know if it's working as you'd expect!
from laravel-shopr.
Finally got around to test it, and it seems to work perfectly! Good job :) 👍
from laravel-shopr.
No problem!
from laravel-shopr.
Related Issues (15)
- Facades for Cart and Coupons HOT 1
- Validation error when applying a coupon HOT 2
- Cart discounts is not applied to updated items HOT 3
- Include the discounted amount on the $order HOT 3
- If a transaction fails, the cart should not be cleared and no order should be created
- Support Stripe Strong Customer Authentication (SCA) HOT 1
- Subtotal/Tax Calculations HOT 1
- Class 'NumberFormatter' not found HOT 1
- Allows to configure routes HOT 4
- Call to undefined method Illuminate\Events\Dispatcher::fire() HOT 2
- Configure whether tax should be based on gross or net prices HOT 1
- Laravel 6 compatability
- Laravel 7 support
- Discount coupons HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-shopr.