Comments (26)
im guessing your using the wrong totals to get what your asking for , there are a lot of different totals , also taxes are complicated and theres alot of configurations for it.
Pre taxed coupons vs non pretaxed etc.
ill make it a test and verify what your saying
from laracart.
sorry i didnt read all of that, i cant meet right now, but ill make a test and post it here ~
from laracart.
yah the changes you made probably work, but i hvae to fix my tests to make sure i dont break anything else .
This package is also VERY old , im 100% sure i could have written it better 😆
from laracart.
no worries, ill see if i can get to fixing the tests tonight, I ran out of time and have todo the real work that pays the $$$
from laracart.
It works if I update this function in LaraCart :
private function updateDiscounts()
{
// reset discounted
foreach ($this->getItems() as $item) {
$item->discounted = [];
}
// go through each item and see if they have a coupon attached
foreach ($this->getItems() as $item) {
if ($item->coupon) {
$item->coupon->discounted = 0;
for ($qty = 0; $qty < $item->qty; $qty++) {
$item->coupon->discounted += $item->discounted[$qty] = $item->coupon->discount($item->subTotalPerItem(false));
}
}
}
// go through each coupon and apply to items that do not have a coupon attached
$coupon_item = null;
foreach ($this->getItems() as $item) {
if (!$item->coupon) {
$coupon_item = $item;
break;
}
}
$i = 0;
foreach ($this->getCoupons() as $coupon) {
$coupon->discounted = 0;
$coupon->discounted += $coupon_item->discounted[$i] = $coupon->discount($this->subTotal(false));
$i++;
if (config('laracart.discount_fees', false)) {
// go through each fee and discount
foreach ($this->getFees() as $fee) {
$coupon->discounted = $fee->discounted = $coupon->discount($fee->amount);
}
}
}
}
from laracart.
can you create a test , and ill look at it here soon
from laracart.
Sorry I'm not able to figure out how this could be done, but I can send PR.
Also, regarding tax calculation, I have this use case :
- Add product price 500 ==> Cart Total : 500
- Add coupon 1 :
Coupon 1 : Fixed 60 ==> Cart Total : 500 - 60 = 440 - Tax auto calculated : 15 % ==> 440 * 15 / 100 = 66 ==> Cart Total : 440 + 66 = 506
- Add coupon 2:
Coupon 2 : Fixed 40 ==> Cart Total : 506 - 40 = 466 - Add coupon 3 :
Coupon 3 : Percentage 10 % ==> 500 * 10 / 100 ==> 50 ==> Cart Total : 466 - 50 = 416
Is this correct ? I think the correct totals should be like this :
Cart Total - sum(coupons) + tax
Cart Total - sum(coupons) = 500 - (60+40+50) = 350
Tax = 350 * 15 / 100 = 52.5
Final Total = 350 + 52.5 = 402.5
Am I correct ? thanks
from laracart.
Thanks for quick reply,
If you don't mind, I can share with you my work (via google meet share screen) and check what I'm doing as use cases
from laracart.
yah sure that would be helpful!
from laracart.
ok i found the issue, multiple coupons arent working as intended , as you pointed above your fix works
from laracart.
related #314
from laracart.
ive added the test and verified the fix works, i changed the code slightly from what you had
from laracart.
Thanks,
Other thing, what if an item has its own coupon ? I didn't test it yet and I think this piece of code should be fixed too :
foreach ($this->getItems() as $item) {
if ($item->coupon) {
$item->coupon->discounted = 0;
for ($qty = 0; $qty < $item->qty; $qty++) {
$item->coupon->discounted += $item->discounted[$qty] = $item->coupon->discount($item->subTotalPerItem(false));
}
}
}
from laracart.
i have an issue with taxes , im still working on it , not sure how long it will take
from laracart.
my current version of the main branch has broken tests so its making this kinda difficult
from laracart.
1) CouponsTest::testSetDiscountOnItem
Failed asserting that 96.3 matches expected 96.30000000000001.
/Users/luke/Code/opensource/laracart/tests/CouponsTest.php:238
phpvfscomposer:///Users/luke/Code/opensource/laracart/vendor/phpunit/phpunit/phpunit:60
2) CouponsTest::testFeeDiscount
Failed asserting that 15.0 matches expected 10.
/Users/luke/Code/opensource/laracart/tests/CouponsTest.php:436
phpvfscomposer:///Users/luke/Code/opensource/laracart/vendor/phpunit/phpunit/phpunit:60
3) ItemsTest::testItemPriceAndQty
Failed asserting that 32.099999999999994 matches expected 32.1.
/Users/luke/Code/opensource/laracart/tests/ItemsTest.php:178
phpvfscomposer:///Users/luke/Code/opensource/laracart/vendor/phpunit/phpunit/phpunit:60
4) SubItemsTest::testTaxSumary
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- '0.01' => 0.1
- '0.02' => 0.2
+ 0 => Array (...)
)
/Users/luke/Code/opensource/laracart/tests/SubItemsTest.php:322
phpvfscomposer:///Users/luke/Code/opensource/laracart/vendor/phpunit/phpunit/phpunit:60
5) TotalsTest::testTaxationOnCoupons
Failed asserting that 419.02 matches expected 419.12.
/Users/luke/Code/opensource/laracart/tests/TotalsTest.php:342
phpvfscomposer:///Users/luke/Code/opensource/laracart/vendor/phpunit/phpunit/phpunit:60
from laracart.
Thanks, Other thing, what if an item has its own coupon ? I didn't test it yet and I think this piece of code should be fixed too :
foreach ($this->getItems() as $item) { if ($item->coupon) { $item->coupon->discounted = 0; for ($qty = 0; $qty < $item->qty; $qty++) { $item->coupon->discounted += $item->discounted[$qty] = $item->coupon->discount($item->subTotalPerItem(false)); } } }
Try to fix this too,
from laracart.
This :
for ($qty = 0; $qty < $item->qty; $qty++) {
Why are you looping on item qty ? what's the difference if I have item1 qty = 1 or qty 5 ?
from laracart.
tax can happen per item, if thats the case each qty really means a unique item
from laracart.
Using my changes, it works like a charm,
This is a use case :
- Add item 500 twice
- Add coupon 5% discount = 50
- Add coupon 10% discount = 100
- Taxes calculation 15% : (500*2 - 50 -100) *0.15 = 127.5
- Total = 850 + 127.5 = 977.5
Am I wrong ?
from laracart.
tax can happen per item, if thats the case each qty really means a unique item
Why you don't add tax to sum(item->qty) instead of tax on each qty = 1 ?
Tax on Qty=5 === Tax on Qty1 + Tax on Qty1 ....+ Tax on Qty5
from laracart.
if you allow taxation on discounts you have to be careful as tax on qty5 1= tax on qty 1 + qty 2 + ..
from laracart.
also taxation on fees runs into this same issue~
from laracart.
Using my changes, it works like a charm, This is a use case :
1. Add item 500 twice 2. Add coupon 5% discount = 50 3. Add coupon 10% discount = 100 4. Taxes calculation 15% : (500*2 - 50 -100) *0.15 = 127.5 5. Total = 850 + 127.5 = 977.5
Am I wrong ?
Could you please tell if it's correct ? I'm applying tax on cart totals
from laracart.
if your in the U.S it will depend on your state , id look up your guidelines for how taxation works etc. (taxation sucks and its more complicated than id liek)
from laracart.
I see it's a headache :/
My use case is a normal tax application, not in US
from laracart.
Related Issues (20)
- Sub Items should inherit tax from item HOT 1
- Tax Summary Broken
- Discount Value is rounded
- CartItem total() does not consider coupon/discount
- Return this cart item (when adding associate model). HOT 1
- Return this cart item (when adding associate model). HOT 2
- setting a discount for each item in the cart HOT 1
- Laravel authentication stopped working after using this package (User get logout). HOT 2
- setting a discount for each item in the cart HOT 2
- Tax Summary Broken HOT 1
- Simpler get, update and remove HOT 1
- item_model_bindings relation.name not working HOT 2
- PHP 8.0 your php version (8.0.9) does not satisfy that requirement. HOT 1
- Problems faced in getItem() & removeItem() HOT 1
- php8.1 problems HOT 4
- error with composer HOT 3
- Unable to apply several percentage coupons HOT 7
- Manage promotion Buy x Get Y HOT 2
- how to use laracart without login HOT 12
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 laracart.