-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-api): Add channel support for products (#968)
- Loading branch information
Showing
9 changed files
with
93 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/store-api/src/platforms/vtex/clients/commerce/index.ts
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
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export interface SelectedFacet { | ||
key: string | ||
value: string | ||
} | ||
|
||
const getIdFromSlug = (slug: string) => { | ||
const id = slug.split('-').pop() | ||
|
||
if (id == null) { | ||
throw new Error('Error while extracting sku id from product slug') | ||
} | ||
|
||
return id | ||
} | ||
|
||
/** | ||
* Transform facets from the store to VTEX platform facets. | ||
* For instance, the channel in Store becames trade-policy in VTEX's realm | ||
* */ | ||
export const transformSelectedFacet = ({ key, value }: SelectedFacet) => { | ||
switch (key) { | ||
case 'channel': | ||
return { key: 'trade-policy', value } | ||
|
||
case 'slug': | ||
return { key: 'id', value: getIdFromSlug(key) } | ||
|
||
default: | ||
return { key, value } | ||
} | ||
} |
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