Created
October 5, 2023 09:08
-
-
Save dev-prakhar/a27f9c92a6d1d26cf64140c97f6918b5 to your computer and use it in GitHub Desktop.
Basic Cart Transform Function
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
| // @ts-check | |
| /** | |
| * @typedef {import("../generated/api").InputQuery} InputQuery | |
| * @typedef {import("../generated/api").FunctionResult} FunctionResult | |
| */ | |
| /** | |
| * @type {FunctionResult} | |
| */ | |
| const NO_CHANGES = { | |
| operations: [] | |
| }; | |
| export default /** | |
| * @param {InputQuery} input | |
| * @returns {FunctionResult} | |
| */ | |
| (input) => { | |
| const cartLines = input.cart.lines.map(line => { | |
| return { | |
| cartLineId: line.id, | |
| quantity: line.quantity | |
| } | |
| }) | |
| return { | |
| operations: [ | |
| { | |
| merge: { | |
| cartLines: cartLines, | |
| price: { | |
| percentageDecrease: { | |
| value: 10 | |
| } | |
| }, | |
| title: 'My Bundle Title', | |
| parentVariantId: input.cart.lines[0].merchandise?.id | |
| } | |
| } | |
| ] | |
| } | |
| }; |
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
| query Input { | |
| cart { | |
| lines { | |
| id | |
| quantity | |
| merchandise { | |
| ... on ProductVariant { | |
| id | |
| sku | |
| product { | |
| id | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment