Skip to content
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

Merged
merged 9 commits into from
Oct 25, 2018

Conversation

Roywcm
Copy link
Contributor

@Roywcm Roywcm commented Oct 24, 2018

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.

@lukepolo
Copy link
Owner

lukepolo commented Oct 24, 2018

AWESOME ! 🎉 , waiting for tests to pass once passing ill merge.

@lukepolo
Copy link
Owner

Seems travis is having issues with composer install.

@Roywcm
Copy link
Contributor Author

Roywcm commented Oct 24, 2018

I see, but I didn't changed anything to composer.
Also, as noticed, some tests failed already in the main branch.

@lukepolo
Copy link
Owner

Will look at it tonight to see if i can fix it.

@lukepolo
Copy link
Owner

I fixed travis , but there are two errors we need to fix before moving on :

https://travis-ci.org/lukepolo/laracart/jobs/446187520

Event::assertDispatched('laracart.addItem', function ($e, $item) use ($cartItem) {
return $item === $cartItem;
});
Event::assertDispatched('laracart.addItem', 1);
Copy link
Owner

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?

Copy link
Owner

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)

Event::assertDispatched('laracart.updateItem', function ($e, $eventItem) use ($item) {
return $eventItem['item'] === $item && $eventItem['newHash'] === $item->getHash();
});
Event::assertDispatched('laracart.updateItem', 1);
Copy link
Owner

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?

Copy link
Owner

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);

Copy link
Contributor Author

@Roywcm Roywcm Oct 25, 2018

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.

Copy link
Owner

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

Copy link
Contributor Author

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.

@lukepolo lukepolo merged commit d527152 into lukepolo:master Oct 25, 2018
@Roywcm
Copy link
Contributor Author

Roywcm commented Oct 25, 2018

Thnx!

@lukepolo
Copy link
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants