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

feat: Trade Policies #1319

Merged
merged 1 commit into from
May 31, 2022
Merged

feat: Trade Policies #1319

merged 1 commit into from
May 31, 2022

Conversation

tlgimenes
Copy link
Contributor

@tlgimenes tlgimenes commented May 25, 2022

What's the purpose of this pull request?

This PR uses VTEX Session to add full support for trade policies on FastStore

How it works?

We currently support a single trade policy by store on FastStore. You can configure your default trade policy at store.config.js.
Supporting multiple sales channels means we are able to automatically detect and change the channel based on multiple parameters, like user and urls.

To make this auto detection possible, I made the Session context provider behave like the Cart provider. This means that it now accepts a new function called onValidateSession. This functions calls the backend to validate the session. The backend, then, changes/validates the session and updates values like channel, person, language, etc.
On any change to the channel (because the user is logged in, for instance) the session is updated and the user starts browsing on this new session.

To make all work, I:

  • Changed user for person on Session Context. Now person can be accessed by session.person
  • Removed the person query, since the person data is updated automatically on Session context
  • Renamed updateSession mutation in favor of validateSession
  • Forwards user's querystring to VTEX Session request, so session s updated accordingly.

How to test it?

Test1:

  1. Change the account on store.config.js from storeframework to storecomponents
  2. Run locally with yarn develop
  3. Visit /apparel---accessories. Make sure the list of products appear
  4. Visit /apparel---accessories?sc=2. Make sure the product list changes.

Test2:

  1. Change the account on store.config.js from storeframework to storecomponents
  2. Run locally with yarn develop
  3. Visit the product FASTSHOP TESTE HUB HML
  4. Now, visit this path with ?sc=2. Make sure the currency changed

Starters Deploy Preview

Future work

Requests for search api should wait for session validation. Currently these starters don't wait, causing possible flickering on the screen, since some products may appear and disappear (due to session being revalidated). Future work should include waiting for session validation before any requests.

@tlgimenes tlgimenes requested a review from a team as a code owner May 25, 2022 17:32
@vercel
Copy link

vercel bot commented May 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
faststore ✅ Ready (Inspect) Visit Preview May 31, 2022 at 5:27PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 25, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5b67df2:

Sandbox Source
Store UI Typescript Configuration

@vercel
Copy link

vercel bot commented May 25, 2022

Deployment failed with the following error:

Resource is limited - try again in 5 minutes (more than 100, code: "api-deployments-free-per-day").

const postalCode = String(oldSession.postalCode ?? '').replace(/\D/g, '')
const country = oldSession.country ?? ''

const [regionData, sessionData] = await Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

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

Change promise.all to promise.allSettled

Copy link
Member

Choose a reason for hiding this comment

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

why allSettled is better in this case @igorbrasileiro?

@tlgimenes tlgimenes changed the title WIP | feat: Trade Policies feat: Trade Policies May 26, 2022
@tlgimenes tlgimenes force-pushed the chore/sales-channel branch from 43b859c to 5b67df2 Compare May 31, 2022 17:23
@tlgimenes tlgimenes merged commit 09cda0e into main May 31, 2022
@tlgimenes tlgimenes deleted the chore/sales-channel branch May 31, 2022 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants