diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c2ca158..5b84d23f9 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [0.0.1-rtw.15] - Q2/2024 +Apr-16 - Removed duplicate netlify.toml and netlify directory (the ones in the higher-most directory) Apr-16 - Missing netlify.toml file and netlify directory, I suspect. I placed it in both the directory and build directory e.g. static/11ty-store/petstuff - Note this is no longer an 11ty-store. Also, failing this there's apparently also Hydrogen-react https://shopify.dev/docs/api/hydrogen-react Apr-15 - Figured it out - I think. Let's see Apr-15 - Left out the hidden files in the new 11ty-store. Re-instated them, now Netlify should build the store ok diff --git a/static/11ty-store/netlify.toml b/static/11ty-store/netlify.toml deleted file mode 100755 index 4cce6a459..000000000 --- a/static/11ty-store/netlify.toml +++ /dev/null @@ -1,22 +0,0 @@ -[build] - publish = "dist" - command = "npm run build" - -[dev] - publish = "./dist" - command = "npm run serve" - -[[redirects]] - from = "/api/*" - to = "/.netlify/functions/:splat" - status = 200 - -[[redirects]] - from = "/cart" - to = "/.netlify/functions/cart-view" - status = 200 - - -[context.production] - environment = { SHOPIFY_API_ENDPOINT = "https://shop.datro.xyz/api/unstable/graphql.json", SHOPIFY_STOREFRONT_API_TOKEN = "e9c4dbd5f540d4cefcb2518f7648caf9" } - diff --git a/static/11ty-store/netlify/functions/add-to-cart.js b/static/11ty-store/netlify/functions/add-to-cart.js deleted file mode 100755 index 387dbe6e7..000000000 --- a/static/11ty-store/netlify/functions/add-to-cart.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Add to Cart API Endpoint - * - * * Purpose: Add a single item to the cart - * @param {string} cartId (Optional) - * @param {string} itemId - Usually it's the product variant id - * @param {number} quantity - Minimum 1 - * - * @returns {object} cart that contains lines of items inside - * See './utils/createCartWithItem' for the data structure - * - * Examples: - * - * If a cart does not exist yet, - * ``` - * fetch('/.netlify/functions/add-to-cart', { - * method: 'POST', - * body: JSON.stringify({ - * cardId: '', // cardId can also be omitted if desired - * itemId: 'Z2lkOi8vc2hvcGlmFyaWFudC8zOTc0NDEyMDEyNzY5NA==', - * quantity: 4 - * }) - * }) - * ``` - * - * Add item to an existing cart - * ``` - * fetch('/.netlify/functions/add-to-cart', { - * method: 'POST', - * body: JSON.stringify({ - * cartId: 'S9Qcm9kdWN0VmFyaWFudC8zOTc0NDEyMDEyNzY5NA', - * itemId: 'Z2lkOi8vc2hvcGlmFyaWFudC8zOTc0NDEyMDEyNzY5NA==', - * quantity: 4 - * }) - * }) - * ``` - */ - -const { createCartWithItem } = require('./utils/createCartWithItem') -const { addItemToCart } = require('./utils/addItemToCart') - -exports.handler = async (event) => { - let { cartId, itemId, quantity } = JSON.parse(event.body) - quantity = parseInt(quantity); - - - if (cartId) { - console.log('--------------------------------') - console.log('Adding item to existing cart...') - console.log('--------------------------------') - - const shopifyResponse = await addItemToCart({ - cartId, - itemId, - quantity, - }) - - return { - statusCode: 200, - body: JSON.stringify(shopifyResponse.cartLinesAdd.cart), - } - } else { - console.log('--------------------------------') - console.log('Creating new cart with item...') - console.log('--------------------------------') - - console.log(itemId, quantity); - - const createCartResponse = await createCartWithItem({ - itemId, - quantity, - }) - - return { - statusCode: 200, - body: JSON.stringify(createCartResponse.cartCreate.cart), - } - } -} diff --git a/static/11ty-store/netlify/functions/cart-view.js b/static/11ty-store/netlify/functions/cart-view.js deleted file mode 100755 index 284b70956..000000000 --- a/static/11ty-store/netlify/functions/cart-view.js +++ /dev/null @@ -1,202 +0,0 @@ -const fetch = require('node-fetch'); - - -exports.handler = async (event) => { - - const rootURL = process.env.URL || "https://localhost:8888"; - - const cartId = event.queryStringParameters.cartId; - const result = await fetch(`${rootURL}/api/get-cart`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - cartId: cartId - }), - }) - .then((res) =>{ - return res.json() - }); - - - const itemTotal = function(price, quantity) { - const totalPrice = Number(price) * Number(quantity) - return totalPrice.toFixed(2) - } - - - const cartItem = (cartId, item) => { - const displayTitleModifier = item.merchandise.title == "Default Title" ? "" : item.merchandise.title; - return ` - - - ${ item.merchandise.product.title } (${ item.merchandise.title }) - - - - ${item.merchandise.priceV2.amount} - - ${ item.quantity } - - ${ itemTotal(item.merchandise.priceV2.amount, item.quantity) } - - -
- - - -
- - -`}; - - const cartTotals = (cart) => { - - if (!cart.lines.edges.length) { - console.log(`No basket`); - return `
-
- What you need is some meats and cheeses! -
-
`; - } - - return ` -
-
-

- Subtotal: -

-

Shipping:

-

Tax:

-

Total:

-
-
-

- ${cart.estimatedCost.subtotalAmount.amount} ${cart.estimatedCost.totalAmount.currencyCode} -

-

Free Shipping

-

${cart.estimatedCost.totalTaxAmount.amount} ${cart.estimatedCost.totalAmount.currencyCode}

-

${cart.estimatedCost.totalAmount.amount} ${cart.estimatedCost.totalAmount.currencyCode}

-
-
`; - } - - - let items = ""; - result.cart.lines.edges.forEach(item => { - items += cartItem(result.cart.id, item.node) - }); - - - - - const pageTemplate = (items, totals) => {return ` - - - - Your Cart - - - -
-

Shoperoni

- -
-
-
-
-

Your Cart

-
- - - - - - - - - - ${items} - -
ItemPriceQuantityTotalActions
-
- ${cartTotals(result.cart)} -
-
-
-
-
- - - - - `}; - - return { - statusCode: 200, - body: pageTemplate(items, result.cart.estimatedCost) - }; - -} \ No newline at end of file diff --git a/static/11ty-store/netlify/functions/get-cart.js b/static/11ty-store/netlify/functions/get-cart.js deleted file mode 100755 index 6e10159c0..000000000 --- a/static/11ty-store/netlify/functions/get-cart.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * API Endpoint - * - * * Purpose: Get items from an existing cart - * @param {string} cartId - * - * Example: - *``` - * fetch('/.netlify/functions/get-cart', { - * method: 'POST', - * body: JSON.stringify({ cartId: '12345' }) - * }) - * ``` - * - * ! POST method is intentional for future enhancement - * - * TODO: Add enhancement for pagination - */ - -const { postToShopify } = require('./utils/postToShopify') - -exports.handler = async (event) => { - const { cartId } = JSON.parse(event.body); - try { - console.log('--------------------------------') - console.log('Retrieving existing cart...') - console.log('--------------------------------') - const shopifyResponse = await postToShopify({ - query: ` - query getCart($cartId: ID!) { - cart(id: $cartId) { - id - lines(first: 10) { - edges { - node { - id - quantity - merchandise { - ... on ProductVariant { - id - title - priceV2 { - amount - currencyCode - } - product { - title - handle - images(first: 1) { - edges { - node { - src - altText - } - } - } - } - } - } - } - } - } - estimatedCost { - totalAmount { - amount - currencyCode - } - subtotalAmount { - amount - currencyCode - } - totalTaxAmount { - amount - currencyCode - } - totalDutyAmount { - amount - currencyCode - } - } - } - } - `, - variables: { - cartId, - }, - }) - return { - statusCode: 200, - body: JSON.stringify(shopifyResponse), - } - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/netlify/functions/remove-from-cart.js b/static/11ty-store/netlify/functions/remove-from-cart.js deleted file mode 100755 index 6f4a222bb..000000000 --- a/static/11ty-store/netlify/functions/remove-from-cart.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Remove Item From Cart API Endpoint - * - * * Purpose: Remove a single item from the cart - * @param {string} cartId - * @param {string} lineId - Not the item or variant id - * - * Example: - * ``` - * fetch('/.netlify/functions/remove-from-cart, { - * method: 'POST', - * body: JSON.stringify({ - * cartId: 'S9Qcm9kdWN0VmFyaWFudC8zOTc0NDEyMDEyNzY5NA', - * lineId: 'RIJC3mn0c862e2fc3314ba5971bf22d73d7accb' - * }) - * }) - * ``` - */ - -const { removeItemFromCart } = require('./utils/removeItemFromCart') -const querystring = require("querystring"); - -exports.handler = async (event) => { - - if (event.httpMethod !== "POST") { - return { statusCode: 405, body: "Method Not Allowed" }; - } - const { cartId, lineId } = querystring.parse(event.body) - try { - console.log('--------------------------------') - console.log('Removing item from cart...') - console.log('--------------------------------') - const shopifyResponse = await removeItemFromCart({ - cartId, - lineId, - }) - - return { - statusCode: 302, - headers: { - Location: `/cart/?cartId=${cartId}`, - }, - } - - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/netlify/functions/utils/addItemToCart.js b/static/11ty-store/netlify/functions/utils/addItemToCart.js deleted file mode 100755 index 75c138ab6..000000000 --- a/static/11ty-store/netlify/functions/utils/addItemToCart.js +++ /dev/null @@ -1,70 +0,0 @@ -const { postToShopify } = require('./postToShopify') - -exports.addItemToCart = async ({ cartId, itemId, quantity }) => { - try { - const shopifyResponse = postToShopify({ - query: ` - mutation addItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { - cartLinesAdd(cartId: $cartId, lines: $lines) { - cart { - id - lines(first: 10) { - edges { - node { - id - quantity - merchandise { - ... on ProductVariant { - id - title - priceV2 { - amount - currencyCode - } - product { - title - handle - } - } - } - } - } - } - estimatedCost { - totalAmount { - amount - currencyCode - } - subtotalAmount { - amount - currencyCode - } - totalTaxAmount { - amount - currencyCode - } - totalDutyAmount { - amount - currencyCode - } - } - } - } - } - `, - variables: { - cartId, - lines: [ - { - merchandiseId: itemId, - quantity, - }, - ], - }, - }) - - return shopifyResponse - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/netlify/functions/utils/createCartWithItem.js b/static/11ty-store/netlify/functions/utils/createCartWithItem.js deleted file mode 100755 index 2b0226ed0..000000000 --- a/static/11ty-store/netlify/functions/utils/createCartWithItem.js +++ /dev/null @@ -1,74 +0,0 @@ -const { postToShopify } = require('./postToShopify') - -// Creates a cart with a single item -exports.createCartWithItem = async ({ itemId, quantity }) => { - try { - const response = await postToShopify({ - query: ` - mutation createCart($cartInput: CartInput) { - cartCreate(input: $cartInput) { - cart { - id - createdAt - updatedAt - lines(first:10) { - edges { - node { - id - quantity - merchandise { - ... on ProductVariant { - id - title - priceV2 { - amount - currencyCode - } - product { - id - title - } - } - } - } - } - } - estimatedCost { - totalAmount { - amount - currencyCode - } - subtotalAmount { - amount - currencyCode - } - totalTaxAmount { - amount - currencyCode - } - totalDutyAmount { - amount - currencyCode - } - } - } - } - } - `, - variables: { - cartInput: { - lines: [ - { - quantity, - merchandiseId: itemId, - }, - ], - }, - }, - }) - - return response - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/netlify/functions/utils/postToShopify.js b/static/11ty-store/netlify/functions/utils/postToShopify.js deleted file mode 100755 index 1ebfdf263..000000000 --- a/static/11ty-store/netlify/functions/utils/postToShopify.js +++ /dev/null @@ -1,28 +0,0 @@ -const fetch = require('node-fetch'); - - -require('dotenv').config(); -exports.postToShopify = async ({ query, variables }) => { - try { - const result = await fetch(process.env.SHOPIFY_API_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Shopify-Storefront-Access-Token': - process.env.SHOPIFY_STOREFRONT_API_TOKEN, - }, - body: JSON.stringify({ query, variables }), - }).then((res) => res.json()) - - if (result.errors) { - console.log({ errors: result.errors }) - } else if (!result || !result.data) { - console.log({ result }) - return 'No results found.' - } - - return result.data - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/netlify/functions/utils/removeItemFromCart.js b/static/11ty-store/netlify/functions/utils/removeItemFromCart.js deleted file mode 100755 index 9aa82d6d5..000000000 --- a/static/11ty-store/netlify/functions/utils/removeItemFromCart.js +++ /dev/null @@ -1,69 +0,0 @@ -const { postToShopify } = require('./postToShopify') - -/** - * @param {string} cartId - Target cart to update - * @param lineId - Line id that the item belongs to - */ -exports.removeItemFromCart = async ({ cartId, lineId }) => { - try { - const shopifyResponse = await postToShopify({ - query: ` - mutation removeItemFromCart($cartId: ID!, $lineIds: [ID!]!) { - cartLinesRemove(cartId: $cartId, lineIds: $lineIds) { - cart { - id - lines(first: 10) { - edges { - node { - id - quantity - merchandise { - ... on ProductVariant { - id - title - priceV2 { - amount - currencyCode - } - product { - title - handle - } - } - } - } - } - } - estimatedCost { - totalAmount { - amount - currencyCode - } - subtotalAmount { - amount - currencyCode - } - totalTaxAmount { - amount - currencyCode - } - totalDutyAmount { - amount - currencyCode - } - } - } - } - } - `, - variables: { - cartId, - lineIds: [lineId], - }, - }) - - return shopifyResponse - } catch (error) { - console.log(error) - } -} diff --git a/static/11ty-store/petstuff/netlify.toml b/static/11ty-store/petstuff/netlify.toml index 4cce6a459..7d735e26d 100755 --- a/static/11ty-store/petstuff/netlify.toml +++ b/static/11ty-store/petstuff/netlify.toml @@ -1,9 +1,9 @@ [build] - publish = "dist" + publish = "public" command = "npm run build" [dev] - publish = "./dist" + publish = "./public" command = "npm run serve" [[redirects]] @@ -18,5 +18,5 @@ [context.production] - environment = { SHOPIFY_API_ENDPOINT = "https://shop.datro.xyz/api/unstable/graphql.json", SHOPIFY_STOREFRONT_API_TOKEN = "e9c4dbd5f540d4cefcb2518f7648caf9" } + environment = { SHOPIFY_API_ENDPOINT = "https://4c56cf-e6.myshopify.com/api/unstable/graphql.json", SHOPIFY_STOREFRONT_API_TOKEN = "e9c4dbd5f540d4cefcb2518f7648caf9" } diff --git a/static/11ty-store/public/favicon.svg b/static/11ty-store/public/favicon.svg new file mode 100644 index 000000000..e69de29bb