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

[POS UI Extensions] Return UUID when Cart API's Line item level promises are resolved #1495

Closed
dsnvs opened this issue Nov 2, 2023 · 5 comments
Labels
enhancement New feature or request POS UI Extensions

Comments

@dsnvs
Copy link

dsnvs commented Nov 2, 2023

Please list the related package(s)

retail-ui-extensions

If this related to specific APIs or components, please list them here

Cart API's Line Item Level action

Is your feature request related to a problem? Please describe.

Our apps rely on managing the line items in the cart (add a new line item, remove line item), and with the current Cart API, chained operations are cumbersome and severely increase the complexity of the code.

For example, adding new line items with properties to the cart requires us first to add the line item to the cart, then listen to cart changes to try and identify the new line item (which becomes very tricky for custom sales), so we can grab the new UUID and apply the line item property.

Maybe I am missing something here and there is a simple way to do this, but with my understanding of React Hooks (which is not that high), React Hooks' paradigm combined with the useCartSubscription() hook being limited to one subscriber at a time, doing this is a big hassle. In most scenarios, chaining the actions is not a hard task, but it makes the extension way more complex with data moving in multiple directions and a single context that has to manage the cart.

Describe the changes you are looking for

Having the addLineItem() and addCustomSale() functions reaturn the UUIDs of the line item when the promise is resolved would eliminate this problem almost entirely.

Returning the quantity would also be super helpful so we could remove a line item from the cart if quantity was zero.

Describe alternatives you’ve considered

Additional context

@kyle-villeneuve
Copy link

kyle-villeneuve commented Jul 7, 2024

This is super important for us, without it it leads to a lot of very unidiomatic code.

Just to piggyback onto this... another useful improvement would be setting custom properties as a third argument in addLineItem

@kyle-villeneuve
Copy link

// setup listener before adding to cart

let called = false; // ensure the subscription is only fired once

api.cart.subscribable.subscribe(async ({ lineItems }) => {
  if (called) return;

  const lineItem = lineItems.find((li) => li.variantId === Number(variantId));

  if (lineItem) {
    called = true; // prevent subsequent calls
    
    // do stuff with added lineItem here
    // ...
    
    // set a new listener to "unsubscribe"
    api.cart.subscribable.subscribe(() => {});
  }
});
}

// add to cart, which should trigger the subscriber
await api.cart.addLineItem(Number(variantId), 1);

this is the workaround for now

@adamwooding
Copy link

+1 for this feature. @js-goupil has there been any movement on this? Thanks so much :)

@js-goupil
Copy link
Contributor

@adamwooding no movement yet, but it would have to be a part of the January release. It's a popular ask, and a low hanging fruit so I'll see what I can do to get the ball rolling. My apologies for the lack of response, I've been out for a month, but I'm back now 😄

@vctrchu
Copy link
Contributor

vctrchu commented Dec 18, 2024

@adamwooding @dsnvs @kyle-villeneuve We have updated the addLineItem and addCustomSale to return UUIDS. It will be available for use officially in ui-extension version 2025-01 and POS 9.26 starting on 1/26/2025. Thank you for your patience.

@vctrchu vctrchu closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request POS UI Extensions
Projects
None yet
Development

No branches or pull requests

6 participants