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

W 15586246/removed out of stock product from cart #1881

Merged
merged 22 commits into from
Jul 8, 2024

Conversation

alexvuong
Copy link
Collaborator

@alexvuong alexvuong commented Jul 5, 2024

Description

Some products can be out of stock during shopping journey. We want to make sure out of stock will also removed before allowing shoppers to navigate from Cart to checkout page. At the moment, we have the unavailableModal which will promot shoppers to remove unavailable products, we should include out of stock products

Related issue: #1759

This PR attempted to make #1865 a non-breaking change for UnavailableProductModals

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • (change1)

How to Test-Drive This PR

  • (step1)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)
@alexvuong alexvuong requested a review from a team as a code owner July 5, 2024 21:38
handleUnavailableProducts = noop
}) => {
const unavailableProductIdsRef = useRef(null)
const ids = productIds.length ? productIds : productItems.map((i) => i.productId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this is the main change from the previous PR (#1865)

So now we can either set productIds (the previous API) or productItems (the new API). I think this makes sense to prioritize the current behavior so existing projects will opt in to transition to the new API rather than having the new API forced on them.

@vcua-mobify
Copy link
Contributor

I've verified that I am prompted to remove the item from my basket once I make the item unavailable in BM.

vcua-mobify
vcua-mobify previously approved these changes Jul 5, 2024
Comment on lines 50 to 56
if (
!isWishlist &&
(!inventory?.orderable ||
(inventory?.orderable && productItem?.quantity > inventory.stockLevel))
) {
unOrderableIds.push(id)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the logic here still assumes that productItems prop is passed in. Can we tweak the logic like this?

  • If productIds props is passed in, logic will check for resProductIds only.
  • If productItems is passed in, the logic will check for both resProductIds and unOrderableIds.
…product-from-cart' into W-15586246/removed-out-of-stock-product-from-cart
@alexvuong alexvuong enabled auto-merge (squash) July 8, 2024 20:19
(inventory?.orderable && productItem?.quantity > inventory.stockLevel))
) {
unOrderableIds.push(id)
if (productItems.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Edge case: if both productIds and productItems are passed in, we prioritize using productIds as it is the older behavior that will not break existing implementaions.

But here the condition is to run the extra logic if productItems have been sent in. Should this also have a condition where we don't run this block if productIds have length?

So rather than if (productItems.length) we use if (productItems.length && !productIds.length)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I think here we should have a warning to not allow two props being passed at the same time. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On second thought, if they pass in both productIds and productItem, they will have extra behavior where low stock /out of stock products in basket being removed depends on the productIds that they pass in. I think it should be fine. 🤔

@alexvuong alexvuong merged commit defb4ed into develop Jul 8, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants