-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Phil Hawksworth
committed
Jun 26, 2021
1 parent
2406802
commit 2a9ecdd
Showing
5 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
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,88 @@ | ||
const { postToShopify } = require('../../src/utils/postToShopify'); | ||
const querystring = require('querystring'); | ||
|
||
|
||
exports.handler = async (event) => { | ||
|
||
// Parse the form submission | ||
if (event.httpMethod !== "POST") { | ||
return { statusCode: 405, body: "Method Not Allowed" }; | ||
} | ||
const { | ||
quantity, | ||
merchandiseId | ||
} = querystring.parse(event.body); | ||
|
||
console.log( quantity, merchandiseId); | ||
|
||
|
||
const response = await postToShopify({ | ||
query: `mutation { createCart($cartInput: CartInput}) { | ||
cartCreate(input: $cartInput) { | ||
cart { | ||
id | ||
createdAt | ||
updatedAt | ||
lines(first:10) { | ||
edges { | ||
node { | ||
id | ||
merchandise { | ||
... on ProductVariant { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
attributes { | ||
key | ||
value | ||
} | ||
estimatedCost { | ||
totalAmount { | ||
amount | ||
currencyCode | ||
} | ||
} | ||
} | ||
} | ||
}`, | ||
variables: `{ | ||
"cartInput": { | ||
"lines" : [ | ||
{ | ||
"quantity": "${quantity}", | ||
"merchandiseId": "${merchandiseId}" | ||
} | ||
], | ||
"attributes": { | ||
"key": "cart_attribute", | ||
"value": "Some cart attribute" | ||
} | ||
} | ||
}` | ||
}); | ||
|
||
console.log(response); | ||
|
||
|
||
// Shopify will create a new cart ID if required | ||
const cardId = "DUMMY" | ||
|
||
// Now that an item was added to the cart, take the user to it. | ||
// We'll render this dynamically from a serverless function | ||
return { | ||
body: "", | ||
statusCode: 302, | ||
headers: { | ||
Location: `/cart?cartId=${cardId}`, | ||
} | ||
}; | ||
|
||
|
||
}; | ||
|
||
|
||
|
||
|
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,13 @@ | ||
|
||
exports.handler = async (event) => { | ||
|
||
console.log(event.queryStringParameters); | ||
|
||
const cartId = event.queryStringParameters.cartId; | ||
|
||
return { | ||
statusCode: 200, | ||
body: `view of cart with ID: ${cartId}` | ||
}; | ||
|
||
} |
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