[B2BTEAM-3748] Forward priceToken on addToCart (Pricing Fallback V2) - #17
Open
wender wants to merge 1 commit into
Open
[B2BTEAM-3748] Forward priceToken on addToCart (Pricing Fallback V2)#17wender wants to merge 1 commit into
wender wants to merge 1 commit into
Conversation
Pricing Fallback V2: read the signed price (commertialOffer.PriceToken) from the product context and forward it as priceToken in the addToCart payload, so the Checkout can close the cart while the Pricing is unavailable. The token is read from the seller entry of the very SKU sent on addToCart, since it signs that seller's price for that item, and it is only added to the payload when the search actually returned one, keeping the payload unchanged while search-graphql/product-context do not expose the field yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Beep boop 🤖 I noticed you didn't make any changes at the
In order to keep track, I'll create an issue if you decide now is not a good time
|
|
Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖 Please select which version do you want to release:
And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.
|
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.
What does this PR do? *
Pricing Fallback V2 (B2BTEAM-3748): captures the signed price returned by the search (
items[].sellers[].commertialOffer.PriceToken), read here fromvtex.product-context, and forwards it aspriceTokenin theaddToCartpayload, so the Checkout can close the cart with that price even while the Pricing is unavailable.catalogItemToCart.tsreadscommertialOffer.PriceTokenfrom the seller of the SKU being added and returns it aspriceTokenon the mapped cart item.AddToCartButton.tsx(adjustItemsForMutationInput) sendspriceTokenin thevtex.checkout-resourcesmutation body, alongsideid/index/seller/quantity/options.CommercialOffergains an optionalPriceTokenandOrderFormItemInputan optionalpriceToken.mapCatalogItemToCart.Two deliberate choices:
BuyButton/Wrapper.tsxresolvesselectedSellerfromproductContext.selectedItem.sellers[0], while the item sent to the cart is built from theselectedItemprop — which, when the button is rendered per row bySkuBuyButton, is that row's SKU, not the product context one. So instead of reading the token straight offselectedSeller, it is looked up insideselectedItem.sellersby the already resolvedsellerId. This way the token can never sign the price of a different SKU/seller than the one added to the cart (if no match is found, no token is sent). The pre-existingseller/price/listPriceresolution is left untouched.priceTokenis only added to the payload when the search returns one (conditional spread). While the field is not exposed, the payload is exactly the same as today, and the same applies ifItemInputonvtex.checkout-graphqldoes not acceptpriceTokenyet.Unlike quickorder#185, this app does not own the product query — it only consumes
vtex.product-context— so nothing here breaks on accounts where the field is missing, and this PR is safe to merge before the field is exposed (it simply stays a no-op until then).How to test it? *
Requires an account where
CommertialOffer.PriceTokenis exposed byvtex.search-graphqland the feature flag is enabled (e.g.storeframework), and a theme whose product query requestscommertialOffer { PriceToken }so the field reachesvtex.product-context.vtex linkthe app and open a page withsku-listand its buy button.items[].sellers[].commertialOffer.PriceTokenshould be present.addToCartmutation payload — the item should carrypriceTokenalongsideid,index,seller,quantityandoptions.priceTokenin the payload.cd react && yarn test— themapCatalogItemToCartspecs cover token present, token absent, and seller mismatch.Describe alternatives you've considered, if any. *
selectedSeller. Simpler, but on the per-rowSkuBuyButtonusageselectedSellercomes from the product context item while the SKU sent comes from the row, so it could sign another SKU's price.selectedSellerresolution inWrapper.tsxto always derive from theselectedItemprop. That would also correctprice/listPrice/sellerfor the per-row case, but it is a behaviour change well beyond this ticket and deserves its own investigation.Related to / Depends on *
CommertialOffer.PriceTokenbeing exposed onsearch-resolver/search-graphqland reachingvtex.product-context(not the case yet, per Christian Mutti on 17/07 in the reference thread). Until then this is inert — mergeable, but not verifiable end to end.yarn lintalready fails onmaster(prettier/prettierparsing errors on the optional chaining inSkuHighlights.tsxandSkuSpecifications.tsx, with the pinned Prettier 1.x). Unrelated to this PR —tsc --noEmit, the tests and ESLint on the touched files all pass.