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

Product sets: wishlist (@W-12301966@) #917

Merged
merged 23 commits into from
Jan 26, 2023

Conversation

vmarta
Copy link
Contributor

@vmarta vmarta commented Jan 20, 2023

Updating the wishlist functionality to work with product sets.

For PDP page:

  • Add-to-wishlist callback is more dynamic. It's now accepting a given product (so no longer assume to know which product on the page)

For Account's Wishlist page:

  • Call-to-action button for a product set: show Add All button if the children are not master/variant types. Or else show a button that navigate you to the PDP page.
  • Quantity for product set: when clicking Add All button, the quantity means the number in quantity selector multiplied by the number of items in the set
  • The logic requires setProducts data to exist but it was not available from the getProducts endpoint. So had to fetch the individual products for its setProducts data, but doing it in parallel for better performance.

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)

@vmarta vmarta changed the title Product sets: wishlist Product sets: wishlist (@W-12301966@) Jan 21, 2023
{buttonText.viewOptions}
</Button>
)
// TODO: create a new set in BM to test this scenario
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fine if our main demo instance doesn't have this change yet (we can create a ticket for that) but has this been tested against real data coming back from the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's been tested. I've created the product set in my sandbox and tested it against the API.

Comment on lines 129 to 151
{isOpen && (
<ProductViewModal
isOpen={isOpen}
onOpen={onOpen}
onClose={onClose}
product={variant}
addToCart={(variant, quantity) => handleAddToCart(variant, quantity)}
/>
)}
</>
) : (
<Button
variant={'solid'}
onClick={() => handleAddToCart(variant, variant.quantity)}
w={'full'}
isLoading={isLoading}
>
{buttonText.addToCart}
</Button>
)
}

return button
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I like to avoid using let if at all possible. If you're open to it, I would consider just moving these to immediate returns like this

if (isProductASet) {
  return <>{something}</>
} else if (condition) {
  return <>{somethingElse}</>
} else {
  return <>{default}</>
}

instead of doing let button and then declaring it in if / else block scope

clientId: 'c9c45bfd-0ed3-4aa2-9971-40f88962b836',
organizationId: 'f_ecom_zzrf_001',
clientId: '199c814e-ce47-4af6-a699-b16e2c7b91e7',
organizationId: 'f_ecom_zzrf_009',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change intentional? Maybe I'm missing something but isn't it moving the default to no longer be our demo zzrf_001 instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it was intentional to make it easier for the code reviewer to test the changes. I plan to remove it before the PR is merged.

@@ -55,7 +55,7 @@ module.exports = {
path: 'api'
},
{
host: 'zzrf-001.dx.commercecloud.salesforce.com',
host: 'zzrf-009.dx.commercecloud.salesforce.com',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

Minor comments. No blockers or major concerns. Looks great @vmarta 🎉

@vmarta
Copy link
Contributor Author

vmarta commented Jan 24, 2023

FYI I plan to do the following:

  • On the PDP, make sure the Add To Wishlist button for the individual children works with the child (not the parent)
  • Revert some api config change that was used for debugging/testing

@vmarta vmarta marked this pull request as ready for review January 24, 2023 23:34
@vmarta vmarta requested a review from a team as a code owner January 24, 2023 23:34
Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

Looks good 👌

product.setProducts = data.setProducts
})

productSetFetches.push(promise)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use .map instead of .forEach, you don't need .push 😉

productSetFetches.push(promise)
})

await Promise.allSettled(productSetFetches)
Copy link
Contributor

Choose a reason for hiding this comment

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

This ignores fetches that fail. What happens when some products have setProducts but others don't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question.. it should be Promise.all.

I was thinking of this extending the data with fetched setProducts as something "optional". But actually, that was not accurate.

}
]

const isAddingASet = Boolean(item.setProducts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Boolean() > !! 🙌

try {
await wishlist.createListItem({
id: product.id,
id: product.id || product.productId,
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between product.id and product.productId? Maybe add a comment explaining why we check both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This product is actually either a product or a variant. With variant, its id is called productId. I think I need to be more explicit with the wording here.. have both product and variant.

@vmarta vmarta merged commit f3a4e7d into feature/product-sets Jan 26, 2023
@vmarta vmarta deleted the product-sets-wishlist branch January 26, 2023 02:02
vmarta added a commit that referenced this pull request Mar 1, 2023
* Product sets: basic PLP (#878)

* Show product sets on PLP (alongside other products)

For now, the product sets would look the same as any other kinds of products.

* Parse the product type

* Add todo

* Ignore linting of this line for now

* Add "Starting at" label

* Product sets: basic pdp (@W-12301851@) (#897)

* Product set: render the children products with minimal UI

* No longer showing breadcrumbs in the child items

* Individual swatches now have correct `value`

There was a subtle bug where the `value` of the SwatchGroup was passed down to override all the values of the children Swatch components.

* 1st attempt at saving swatches state in the page url

* Avoid null in the url search params

* Some refactoring

* Add-to-cart now works for child items

* Show accordion for each child item

* Add todo

* Rename variable for accuracy

The child product itself is actually not a set, but is considered a set product.

* Optional argument

* Some refactoring and fix linting

* Helper hook for url search params

* Clean up

* Rename module for a specific use case (PDP)

* Show/hide add-to-cart buttons accordingly

* Modal shows product set data

* Parent product

* Variant's product image shows up in add-to-cart modal

* Rename variables for clarity

* Fix linting error

* Add horizontal rules to separate the parent and child items

* Tweak whitespace

* Localize the Starting At label

* Add todo

* Product sets: wishlist (@W-12301966@) (#917)

* Starting At label

* 1st attempt at updating wishlist for product sets

* "Select Options" → "View Options"

* Some refactoring

* Render add-all-to-cart button if necessary

* Better way to fetch `setProducts` data

* Switch to zzrf-009 temporarily

* For debugging purpose

I'll revert this commit later

* Simpler requirement

* Update what quantity meant for product set

* Some refactoring

* Add comment

* Add-to-wishlist for the individual child items

* Rename variable

* Update button text on PDP

* Update button text on Wishlist page

* Revert "Switch to zzrf-009 temporarily"

This reverts commit 484c8d8.

* PDP: show wishlist button on mobile

* Fix formatting issues (prettier)

* PR feedback

* Clearer as to which is product or variant

* Make it consistent with addToWishlist signature

* [Feature] Add `Add Set to Cart` Button for Product Sets (#931)

* Product sets: basic PLP (#878)

* Variant's product image shows up in add-to-cart modal

* Get modal showing multiple items added to cart

* Add scroll to after validation

Co-authored-by: Vincent Marta <[email protected]>

* Einstein API to support product sets (#962)

* verify viewcategory and viewsearch is working

* viewproduct event is sent for every child product

* addtocart event fires for all children when add set to cart

* parent set only sends id

* Design enhancements for product sets (#975)

* remove complete the set carousel

* remove complete the set translations

* sticky buttons on mobile view

* fix modal vertical margins on desktop

* move recos to modalbody and cleanup margins

* add dividers between product set items in mobile view

* fix margins so sticky buttons do not overlap with content

* add lazy loading of product set children product images

* remove height - does nothing

* bump build size to 55

* add conditional for complete the set and change loading var name

* lint

* revert translations

* Cleanup

* added to cart modal is scrollable and 90% of viewport

* remove dialogprops

* lint

* Testing product sets - @W-12414116@ (#1003)

* Product tile: test product set's price label

* Test product set rendering

* Test callbacks are called properly

* itemAccumulatedCount is redundant

* Test that modal can render multiple products

* Finally the add-to-cart modal shows up in testing

* Clean up

* Test error messages

* Test lazy loading of the child products

* Split a test into smaller ones

* Use `describe` to group all the related tests

* Update comment

* Test the wishlist and its primary action buttons

* Clean up

* Some refactoring

* Some refactoring

* Linting fix

* Update comment

* Test `getDisplayVariationValues`

* Test the usePDPSearchParams

* Tweak another test to pass

Not related to product sets, but needing CI to pass.

* Move mocked data into their own files

* Moving it to within `beforeEach`

---------

Co-authored-by: Ben Chypak <[email protected]>
Co-authored-by: yunakim714 <[email protected]>
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.

3 participants