Skip to content

Commit

Permalink
feat: Consider order number from Checkout cookie (#2592)
Browse files Browse the repository at this point in the history
## What's the purpose of this pull request?

This PR intends to change how we set the order number value on
`@faststore/api`.

## How it works?

Currently, we set the `orderNumber` value as the one we receive from
client-side's storage context. After the order placed, Checkout
generates a new order number (a new cart) and send it through the
`checkout.vtex.com` cookie, but we do not update this value in the
client-side's storage context until the `validateCart` resolver is
executed (in the next `ValidateCartMutation` request). At the resolver,
we always consider the order number's default value as being the one
from client-side's storage context, not the updated one incoming from
Checkout cookie.

So with this change we will consider the order number value from the
`checkout.vtex.com` cookie as the default one, and change the other to
be the fallback case.

## How to test it?

The following store was created to validate the scenario with both
storefront and checkout integrated on the same domain:
https://teste.paladino.co/

Perform the entire checkout flow. The payment type should be with
"money". After the order placed, check the `orderFormId` in
`checkout.vtex.com` cookie, it should be a new one. When returning to
the store also check the `orderFormId` from storage context, it should
be the same as the cookie one. The cart should be empty too.

We need to check if, aside from the order placed flow, everything is
working properly on a current store (use the `starter.store` preview,
with the secure subdomain), add/remove items in the cart, clear the
cart, go to checkout etc.

### Starters Deploy Preview

vtex-sites/starter.store#647

---------

Co-authored-by: Emerson Laurentino <emerson@laurentino.co>
  • Loading branch information
lucasfp13 and emersonlaurentino authored Jan 13, 2025
1 parent 63d9790 commit b1198db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
5 changes: 2 additions & 3 deletions packages/api/src/platforms/vtex/resolvers/validateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ export const validateCart = async (
{ cart: { order }, session }: MutationValidateCartArgs,
ctx: Context
) => {
const orderNumber = order?.orderNumber
? order.orderNumber
: getCookieCheckoutOrderNumber(ctx.headers.cookie, 'checkout.vtex.com')
const orderFormIdFromCookie = getCookieCheckoutOrderNumber(ctx.headers.cookie, 'checkout.vtex.com')
const orderNumber = orderFormIdFromCookie !== '' ? orderFormIdFromCookie : order?.orderNumber

const { acceptedOffer, shouldSplitItem } = order
const {
Expand Down
31 changes: 3 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16869,7 +16869,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -16887,15 +16887,6 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1:
version "2.1.1"
resolved "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz"
Expand Down Expand Up @@ -16990,7 +16981,7 @@ stringify-entities@^4.0.0:
character-entities-html4 "^2.0.0"
character-entities-legacy "^3.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -17018,13 +17009,6 @@ strip-ansi@^5.1.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1, strip-ansi@^7.1.0:
version "7.1.0"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz"
Expand Down Expand Up @@ -18701,7 +18685,7 @@ wordwrap@^1.0.0:
resolved "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz"
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down Expand Up @@ -18735,15 +18719,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz"
Expand Down

0 comments on commit b1198db

Please sign in to comment.