-
Notifications
You must be signed in to change notification settings - Fork 146
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: basic pdp (@W-12301851@) #897
Merged
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
14ffcfb
Product set: render the children products with minimal UI
vmarta c5f71bb
No longer showing breadcrumbs in the child items
vmarta 05cf172
Merge branch 'feature/product-sets' into product-sets-basic-pdp
vmarta 77a2ba6
Individual swatches now have correct `value`
vmarta 3842f9a
Merge branch 'feature/product-sets' into product-sets-basic-pdp
vmarta aa5fdb9
1st attempt at saving swatches state in the page url
vmarta 8400a46
Avoid null in the url search params
vmarta 868a5a3
Some refactoring
vmarta e108963
Add-to-cart now works for child items
vmarta 31bcd93
Show accordion for each child item
vmarta 7d30f54
Add todo
vmarta 9a56c27
Rename variable for accuracy
vmarta a81034f
Optional argument
vmarta 5f5edc6
Some refactoring and fix linting
vmarta b3bd3b2
Helper hook for url search params
vmarta 3acf93d
Clean up
vmarta a670c64
Rename module for a specific use case (PDP)
vmarta 1b2a480
Show/hide add-to-cart buttons accordingly
vmarta e3d27f3
Modal shows product set data
vmarta 5ad9cf4
Parent product
vmarta 9aed81f
Variant's product image shows up in add-to-cart modal
vmarta 41cde1c
Rename variables for clarity
vmarta 5a8f6ce
Fix linting error
vmarta 4ddb22e
Add horizontal rules to separate the parent and child items
vmarta 31aa735
Tweak whitespace
vmarta 1607644
Localize the Starting At label
vmarta 88fb12f
Add todo
vmarta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/template-retail-react-app/app/hooks/use-pdp-search-params.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import {useLocation} from 'react-router-dom' | ||
|
||
export const usePDPSearchParams = (productId) => { | ||
const {search} = useLocation() | ||
|
||
const allParams = new URLSearchParams(search) | ||
const productParams = new URLSearchParams(allParams.get(productId) || '') | ||
|
||
return [allParams, productParams] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,18 @@ const OUT_OF_STOCK = 'OUT_OF_STOCK' | |
const UNFULFILLABLE = 'UNFULFILLABLE' | ||
|
||
// TODO: This needs to be refactored. | ||
export const useProduct = (product) => { | ||
export const useProduct = (product, isProductPartOfSet = false) => { | ||
const showLoading = !product | ||
const stockLevel = product?.inventory?.stockLevel || 0 | ||
const stepQuantity = product?.stepQuantity || 1 | ||
const minOrderQuantity = stockLevel > 0 ? product?.minOrderQuantity || 1 : 0 | ||
const initialQuantity = product?.quantity || product?.minOrderQuantity || 1 | ||
|
||
const intl = useIntl() | ||
const variant = useVariant(product) | ||
const variationParams = useVariationParams(product) | ||
const variationAttributes = useVariationAttributes(product) | ||
const variant = useVariant(product, isProductPartOfSet) | ||
const variationParams = useVariationParams(product, isProductPartOfSet) | ||
const variationAttributes = useVariationAttributes(product, isProductPartOfSet) | ||
// console.log('--- variationAttributes', variationAttributes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to remove this 👍 |
||
const [quantity, setQuantity] = useState(initialQuantity) | ||
|
||
// A product is considered out of stock if the stock level is 0 or if we have all our | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: there was a subtle bug with the original code. Now the parent (SwatchGroup) no longer overriding the children's
value
. They should be distinct.