Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Click "Fetch Collection" to get the collection</h1>
<button id="fetchShop">Fetch Collection</button>
<div id="Products"></div>
              
            
!

CSS

              
                body {
  background-color: #1d1f23;
  color: #809bbd;
}

h1 {
  color: #ddca7e;
}

button {
  background-color: #03dac6;
  border: 0;
  display: block;
  padding: 10px;
}

#Products div {
  margin: 15px 0;
}
              
            
!

JS

              
                const endpoint = 'https://api-demo-store.myshopify.com/api/2020-07/graphql';
const headers = new Headers({
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'X-Shopify-Storefront-Access-Token': 'b8385e410d5a37c05eead6c96e30ccb8'
});

/**
* The request for the data
**/
const getShopifyCollectionByHandle = async () => {
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: headers,
    body: JSON.stringify({query: query()})
  });
  const Collection = await response.json();
  displayCollection(Collection.data.collectionByHandle);
}

/**
* Display some of the results of the query in the DOM
**/
const displayCollection = (Collection) => {
	const H1 = document.getElementsByTagName('h1')[0];
  H1.innerHTML = Collection.title + " | API Demo Store";
  const Products = Collection.products.edges;
  for(let CollectionProduct of Products) {
  	const Product = document.createElement('div');
    Product.innerHTML = `
      Title: ${CollectionProduct.node.title} <br />
      Price: ${CollectionProduct.node.priceRange.minVariantPrice.amount} - ${CollectionProduct.node.priceRange.maxVariantPrice.amount}
    `
    document.getElementById('Products').appendChild(Product);
  }
  document.getElementById('fetchShop').remove();
}

/**
* Bind the function to the button
**/
const Button = document.getElementById('fetchShop');
Button.addEventListener('click', getShopifyCollectionByHandle);

/**
* The graphql query
**/
const query = () => `
{
  collectionByHandle(handle: "mens-glasses") {
    description(truncateAt: 300)
    descriptionHtml
    image {
      altText
      originalSrc
      transformedSrc(maxHeight: 1000, maxWidth: 2048, crop: CENTER)
    }
    title
    products(first: 24) {
      pageInfo {
        hasNextPage
      }
      edges {
        cursor
        node {
          availableForSale
          compareAtPriceRange {
            maxVariantPrice {
              amount
              currencyCode
            }
            minVariantPrice {
              amount
              currencyCode
            }
          }
          handle
          id
          images(first: 1) {
            edges {
              node{
                altText
                transformedSrc(maxWidth: 500, maxHeight: 400, crop: CENTER)
              }
            }
          }
          priceRange {
            maxVariantPrice {
              amount
              currencyCode
            }
            minVariantPrice {
              amount
              currencyCode
            }
          }
          productType
          tags
          title
          totalInventory
          vendor
          variants(first: 100) {
            edges {
              node {
                availableForSale
                compareAtPriceV2 {
                  amount
                  currencyCode
                }
                id
                image {
                  transformedSrc(maxWidth: 500, maxHeight: 400, crop: CENTER)
                }
                priceV2 {
                  amount
                  currencyCode
                }
                quantityAvailable
                title
              }
            }
          }
        }
      }
    }
  }
}
`
              
            
!
999px

Console