-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix for UpdateItem event firing multiple times on add to cart #244
Conversation
AWESOME ! 🎉 , waiting for tests to pass once passing ill merge. |
Seems travis is having issues with composer install. |
I see, but I didn't changed anything to composer. |
Will look at it tonight to see if i can fix it. |
I fixed travis , but there are two errors we need to fix before moving on : |
tests/ItemsTest.php
Outdated
Event::assertDispatched('laracart.addItem', function ($e, $item) use ($cartItem) { | ||
return $item === $cartItem; | ||
}); | ||
Event::assertDispatched('laracart.addItem', 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing errors, did you mean to add this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event::assertDispatched('laracart.addItem', 1)
tests/ItemsTest.php
Outdated
Event::assertDispatched('laracart.updateItem', function ($e, $eventItem) use ($item) { | ||
return $eventItem['item'] === $item && $eventItem['newHash'] === $item->getHash(); | ||
}); | ||
Event::assertDispatched('laracart.updateItem', 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing errors, did you mean to add this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event::assertDispatched('laracart.updateItem', 1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this line is checking if the event is fired once. I was checking this as we speak. I think this line is supported from Laravel 5.6+ and your package is requiring Laravel 5.4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update and remove those versions from being supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Founded another solution. :) I'll commit it in a few seconds.
Thnx! |
Thank you! |
Made this bug fix with tests to prevent UpdateItem to firing multiple times.
The reason was the magic setter which triggered the generateHash method for every new created property. The generateHash method is firing the update event.
I made a check in the magic setter if the property already exists and if so, if the property is changed.
The generateHash method will now only be triggered when a property is changed.
Some tests are failing, but this has nothing to do with my changes.