Repository navigation
feat(commercetools): add product variant picker mode - #11450
Open
Nando Davis (davisnando) wants to merge 2 commits into
Open
Nando Davis (davisnando) wants to merge 2 commits into
Nando Davis (davisnando) wants to merge 2 commits into
Conversation
Adds a `variant` SKU type. Fields configured with it list one row per product variant and store the selected variant SKU, so variants other than the master variant can be referenced. The `product` SKU type stays the default and behaves as before.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
The commercetools app lets editors reference products or categories. For products it always stores the SKU of the master variant, so a specific variant of a product cannot be referenced. Many commercetools projects model sellable options (sizes, colours, configurations) as variants of one product, and editors need to pick those exact variants in Contentful.
This PR adds a
variantSKU type: on fields configured with it, the picker lists product variants and stores the selected variant's SKU.Approach
variant("Product variant") inSKU_TYPES, selectable per field in the app configuration.productstays the default, so existing installations and fields behave exactly as before.src/api/variants.tsfetchVariantsuses the same product projection search asfetchProducts(text search, or thevariants.skufilter when searching by SKU) and turns every product into one row per variant with a SKU, master variant first. A SKU search returns only the matching variant.${productId}:${variantId}, becauseecommerce-app-baseusesidas the list and drag-and-drop key. The name isProduct name (SKU), the image is the variant's first image (falling back to the master variant), and the additional data shows the variant's own attributes. The external link points to the product in the Merchant Center.fetchVariantPreviewsresolves all saved SKUs, including non-master variants, with onevariants.skuquery and returns one row per requested SKU. Unknown SKUs are returned withisMissing: true.createResolver.fetchPreviewsandcreateResolverroute thevarianttype to the new functions.index.tsx), save button and search placeholder texts (dialog.ts) now cover variants ("Select product variants", "Save 3 variants", "Search for a product or variant..."). The "search by SKU" option is also shown for variants.products.tsare now exported so variants reuse them. Product behaviour is unchanged.AGENTS.mddocuments the SKU types, the unique-id requirement and the per-product pagination.Testing steps
apps/commercetools, runnpm run build: the build succeeds.npm startand install the app in a space connected to a commercetools project that has products with several variants.Product name (SKU)).Breaking Changes
None.
variantis opt-in per field andproductremains the default. Values stored by theproducttype are master variant SKUs, so they also resolve when a field is switched tovariant.No dependencies were added
Dependencies and/or References
commercetools-without-searchhas the same architecture and could get the same option in a follow-up if wanted.Deployment
No new installation parameters and no migration. Existing installations keep their configuration; editors opt in by setting a field's SKU type to Product variant.