moltin / laravel-cart

Laravel Facade and Service Provider for Moltin\Cart
276 stars 87 forks source link

Add option with price to Cart::total() #22

Closed jdhrivas closed 10 years ago

jdhrivas commented 10 years ago

So I like to insert the option 'service fee' similar to tax. Which is a percentage of the price. $s = Cart::insert(array( 'id' => 1, 'name' => 'Team Registration', 'price' => 234, 'quantity' => 1, 'tax' => 6, 'service_fee' => 3, 'organization' => 'LAX', 'event' => 1)); Service fee should be 3% of price in this case 7.02 (234*0.03). Now, how can I added the extra fee to Cart::total() ? Thanks!

jHoldroyd commented 10 years ago

I'm not sure if Chris would be happy to add something like this to the package, but in the mean time you could just add another item to the cart like:

$fee  = $cart->insert([
    'name'          => 'Service Fee',
    'price'         => ( $cart->totalWithoutTax() * 0.03 ),
    'quantity'      => 1
    'tax'           => 0,
    'orgranization' => 'LAX',
    'event'         => 1
]);

And then just keep calling it as and when the rest of their cart changes

jdhrivas commented 10 years ago

Good call, It will be awesome to somehow be able to extend the process in future releases. For now your idea will do. Thanks!

jHoldroyd commented 10 years ago

Yeah it's not the most elegant solution in the long term, but it should do for now. I'm sure Chris will have his say on wheather or not this should go in or not though.