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

Refresh cart right after cart_change event (fix #716) #791

Merged
merged 1 commit into from
Jan 9, 2014

Conversation

winzou
Copy link
Contributor

@winzou winzou commented Jan 7, 2014

Refresh the cart with high priority after CART_CHANGE event, so that other listeners are dealing with an updated cart. Fix #716.

@winzou
Copy link
Contributor Author

winzou commented Jan 9, 2014

@pjedrzejewski ping, I need it to move forward on other promotion topics (revert, freeProduct).
(btw Travis is green for php 5.4 & 5.5, red only because of the wtf error with 5.3)

*/
class RefreshCartListener
{
public function onCartChange(GenericEvent $event)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using CartEvent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's a GenericEvent that is dispatched on the cart_change event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe it should be changed to be consistent =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you're right, it could be solved in a better way. I was thinking of doing this in CartEvent:

public function __construct(CartInterface $cart)
{
    $cart->calculateTotal();
    $this->cart = $cart;
}

So that no need to have another listener, and we ensure that the cart is fresh for all other listeners.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add some tests to prevent BC break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stloyd do you know what's the aim of �the isFresh method of CartEvent? https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CartBundle/Event/CartEvent.php#L63

If I refresh the cart directly in the constructor, we should assume that every listener has a fresh cart in its hands. And if it changes something, it's its responsibility to refresh the cart. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winzou TBH. I don't remember what was the point of using non-fresh cart, I guess it was just because of move the code from contollers into listeners.

@pjedrzejewski Do you remember that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really... I'd love to simplify this, especially that when we dispatch cart change event, it always means that something has changed and everything should be recalculated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's address this in another PR.

pjedrzejewski pushed a commit that referenced this pull request Jan 9, 2014
Refresh cart right after cart_change event (fix #716)
@pjedrzejewski pjedrzejewski merged commit 2e6dd76 into Sylius:master Jan 9, 2014
@pjedrzejewski
Copy link
Member

Thanks Alexandre! I'd like to make little changes to the cart listeners and events, but BC should be kept so do not worry.

@winzou winzou deleted the cart-listener branch January 9, 2014 12:27
@winzou
Copy link
Contributor Author

winzou commented Jan 9, 2014

So, @pjedrzejewski you're on it?

@DevOwais
Copy link

DevOwais commented Apr 1, 2020

Hi guys, I am facing this issue. I am using sylius 1.6 and trying to update same product item in the cart but it's not working. can anyone please help me to sort this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cart refreshing on cart change
4 participants