What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello, does anybody know how we can detect any cart change (add/remove) on spryker? We found the `Ca

UPWG9AYH2
UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
edited January 2022 in Help

Hello,
does anybody know how we can detect any cart change (add/remove) on spryker? We found the
CartOperationPostSavePluginInterface
which is described as

  • Specification:
    • This plugin stack is executed after add and remove operations.
    • Returned modified quote is ready to be stored on Client side.

Unfortunately this doesn’t seem to be true since on Operation class beside removeFromCart() and addToCart() it is also called in reloadItemsInQuote() which does not match the promised behaviour in the specification of the interface. reloadItemsInQuote() therefore is also called when there was no change on quote (like on login).

public function reloadItemsInQuote(QuoteTransfer $quoteTransfer):
QuoteResponseTransfer
{
...
$quoteTransfer = $this->executePostSavePlugins($quoteTransfer);
...
}

However we found also a QuoteChangeObserverPluginInterface where we could compare the new and the old QuoteTransfer by ourself but this becomes really unnecessary overhead since in our case we would have to compare all existing items against each other to detect a quantity change for example …
Do we miss something here? So basically we want to react whenever a new item was added, an existing was removed or the quantity of any item was changed.
Best regards

Comments

  • U01K43ADW5N
    U01K43ADW5N Posts: 69 🧑🏻‍🚀 - Cadet
    edited January 2022

    Maybe a CartTerminationPlugin configured for the add and remove events?

  • U01K43ADW5N
    U01K43ADW5N Posts: 69 🧑🏻‍🚀 - Cadet

    the ConfiguredBundleQuantityCartTerminationPlugin does something like you want, I think

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited January 2022

    Seems exactly what we want … i didn’t suppose something useful when i read “termination” … we would just register ADD and REMOVE and it should work … many thanks 😉 have a nice weekend

  • U01K43ADW5N
    U01K43ADW5N Posts: 69 🧑🏻‍🚀 - Cadet

    Just be careful that automatic changes like removing the item from the cart because it does not have stock anymore will not be detected by this approach.

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    Yeah thats okay … we want just to detect any change of the cart the user has made