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
/** | |
INSTRUCTIONS | |
This gist relates to the Gadget quickstart, available here - https://docs.gadget.dev/guides/getting-started/quickstart | |
- get an OpenAI API key (https://openai.com/) | |
- add the key as an OPENAI_API_KEY Environment Variable in your Gadget app (Settings -> Environment Variables) | |
- install the 'openai' npm package (open Gadget command palette, type '>' to enter command mode, enter 'yarn add openai') | |
- paste the following snippet into the code file that runs on the Gadgemon's create action (gadgemon/create/onCreateSuccess.js) | |
*/ |
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
// input.graphql file for a Shopify product discount Function | |
query Input { | |
cart { | |
attribute(key: "addedPrePurchase") { | |
value | |
} | |
lines { | |
quantity | |
merchandise { |
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
const { Configuration, OpenAIApi } = require("openai"); | |
/** | |
* Effect code for update on Shopify Product | |
* @param { import("gadget-server").UpdateShopifyProductActionContext } context - Everything for running this effect, like the api client, current record, params, etc. More on effect context: https://docs.gadget.dev/guides/extending-with-code#effect-context | |
*/ | |
module.exports = async ({ api, record, params, logger, connections }) => { | |
const configuration = new Configuration({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); |
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
<link rel="stylesheet" href="{{ 'section-main-page.css' | asset_url }}" media="print" onload="this.media='all'"> | |
<link rel="stylesheet" href="{{ 'component-rte.css' | asset_url }}" media="print" onload="this.media='all'"> | |
<!-- Find your direct script tag in the Installing section in your Gadget project's API Reference --> | |
<script src="YOUR DIRECT SCRIPT TAG HERE"></script> | |
<script src="{{ 'product-quiz.js' | asset_url }}" defer="defer"></script> | |
<noscript>{{ 'section-main-page.css' | asset_url | stylesheet_tag }}</noscript> | |
<noscript>{{ 'component-rte.css' | asset_url | stylesheet_tag }}</noscript> | |
<div class="page-width page-width--narrow"> | |
<product-quiz class="quiz"> |
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
/** | |
* Fetch the ids for metafields on a resource | |
*/ | |
const fetchMetafieldIds = async ({ resource, shopifyApi, metafieldSchema, id }) => { | |
const gidResource = resource.charAt(0).toUpperCase() + resource.slice(1); | |
const gid = `gid://shopify/${gidResource}/${id}`; | |
return ( | |
await shopifyApi.graphql( | |
` | |
query MetafieldIds($id: ID!) { |