Skip to main content
  1. All Posts/

shopper

eCommerce TypeScript

šŸ›’ shopper

šŸš€ live demo of shopper

šŸ•¹ļø also see the codepen demo
šŸ’° plug your shopify store onto any website!
šŸ›ļø full shopping cart experience with shopify checkout button
āœØ easy html installation! works on any website
šŸ’± users get currency conversions to view prices
šŸ’– free and open source, just for you

āœØ easy html install

  1. add <script> elements in your html <head>

    <script type="importmap-shim">
      {"imports": {
        "shopper/": "https://unpkg.com/shopper@0.2/",
        "shopper": "https://unpkg.com/shopper@0.2/x/shopper.js"
      }}
    </script>
    <script type="importmap-shim" src="https://unpkg.com/shopper@0.2/x/importmap-cloud.json"></script>
    

    <script defer type=module-shim> import “shopper/x/install-xiome-menu-system.js” import “shopper/x/install-shopper.js” </script>

    <script defer src=“ https://unpkg.com/es-module-shims@1.5/dist/es-module-shims.wasm.js"></script>

    <p>
      note: this technique uses es-module-shims, and if you&#8217;re already using es-module-shims for something else on the page, just don&#8217;t repeat that last line (you only want that once per page). </li> 
      
      <li>
        <strong>place a <code>&lt;shopper-config&gt;</code> element in your html <code>&lt;head&gt;</code></strong></p> <pre>&lt;shopper-config
    

    mock base-currency=“cad” currencies=“usd gbp eur” ></shopper-config>

        <p>
          the above config is in <code>mock</code> mode, which lets you play around with fake products<br /> we&#8217;ll explain how to connect your real store in the next section </li> 
          
          <li>
            <strong>place the <code>&lt;shopper-cart&gt;</code> element somewhere on your page</strong><br /> this is all you need</p> <pre>&lt;shopper-cart&gt;&lt;/shopper-cart&gt;</pre>
            
            <p>
              however, you may wish instead to place the cart inside a menu system (like in the demo)
            </p>
            
            <pre>&lt;xio-menu sticky&gt;
    

    <xio-menu-item>

    &lt;shopper-button&gt;&lt;/shopper-button&gt;
    &lt;shopper-cart slot="panel"&gt;&lt;/shopper-cart&gt;
    

    </xio-menu-item> </xio-menu>

            <p>
              also, the cart can take a <code>checkout-in-same-window</code> attribute, if you want to avoid a popup during checkout
            </p>
            
            <pre>&lt;shopper-cart checkout-in-same-window&gt;&lt;/shopper-cart&gt;</pre>
          </li>
          
          <li>
            <strong>list products for sale</strong><br /> list all store products with a <code>&lt;shopper-collection&gt;</code> element and the <code>all</code> attribute<br /> <strong>note:</strong> your products have to be in any collection, for them to appear this way.</p> <pre>&lt;shopper-collection all&gt;&lt;/shopper-collection&gt;</pre>
            
            <p>
              list a single collection. get the <code>link</code> by copying and pasting the url from your shopify admin panel
            </p>
            
            <pre>&lt;shopper-collection link="https://dev-bakery.myshopify.com/admin/collections/424441479"&gt;&lt;/shopper-collection&gt;</pre>
            
            <p>
              display a single product for sale.
            </p>
            
            <pre>&lt;shopper-product link="https://dev-bakery.myshopify.com/admin/products/10232162183"&gt;&lt;/shopper-product&gt;</pre>
            
            <p>
              again, you simply copy the link from the product page&#8217;s url in the shopify dashboard.<br /> you actually don&#8217;t need the whole link, just the numbers from the end part of the url. </li> 
              
              <li>
                <strong>customize the display of products</strong></p> <pre>&lt;shopper-product
    

    link=“10232162183” href="/products/avocado-toast” show-image image-size=“300x200” ></shopper-product>

                <ul dir="auto">
                  <li>
                    <code>link</code> ā€” product url from the shopify admin dashboard
                  </li>
                  <li>
                    <code>href</code> ā€” make the item clickable, taking the user to any url
                  </li>
                  <li>
                    <code>show-image</code> ā€” attach this attribute if you want the product&#8217;s first image to be displayed
                  </li>
                  <li>
                    <code>image-size</code> ā€” specify the dimensions the image should be loaded at</p> <ul dir="auto">
                      <li>
                        if omitted, the image will be full-resolution
                      </li>
                      <li>
                        <code>image-size="200"</code> will constrain the image to <code>200x200</code>
                      </li>
                      <li>
                        <code>image-size="300x200"</code> will constrain the image to <code>300x200</code>
                      </li>
                    </ul>
                  </li>
                </ul>
                
                <pre>&lt;shopper-collection
    

    show-images image-sizes=“300x200” ></shopper-collection>

          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--connect-shopper-to-your-real-shopify-store" class="anchor" aria-hidden="true" href="#-connect-shopper-to-your-real-shopify-store"></a>šŸ“” connect shopper to your real shopify store
          </h2>
          
          <ul dir="auto">
            <li>
              <strong>replace your <code>&lt;shopper-config&gt;</code></strong><br /> use the example below, but use your own values!</p> <pre>&lt;shopper-config

base-currency=“cad” currencies=“usd gbp eur” shopify-domain=“dev-bakery.myshopify.com” shopify-storefront-access-token=“5f636be6b04aeb2a7b96fe9306386f25” ></shopper-config>

            <li>
              <strong>get your <code>baseCurrency</code> correct!</strong><br /> this is the same as your store base currency setting in shopify.
            </li>
            <li>
              <strong>if you provide <code>currencies</code>, they&#8217;ll be available for the user to choose</strong><br /> this is how you specify which currencies you want to allow the currency conversion system to use.<br /> see crnc for more details.
            </li>
            <li>
              <strong>obtain your <code>shopify-domain</code> and <code>shopify-storefront-access-token</code></strong></p> <ul dir="auto">
                <li>
                  login to your shopify store&#8217;s admin area
                </li>
                <li>
                  copy your <code>shopify-domain</code> from your browser address bar&#8217;s url
                </li>
                <li>
                  create a new private app (a connection point for your website) <ol dir="auto">
                    <li>
                      click on the &#8220;apps&#8221; section on the left sidebar
                    </li>
                    <li>
                      click the sneaky &#8220;Manage private apps&#8221; link
                    </li>
                    <li>
                      check on the agreements and stuff to enable private apps
                    </li>
                    <li>
                      click &#8220;Create new private app&#8221;
                    </li>
                    <li>
                      enter the app name, and developer email
                    </li>
                    <li>
                      skip the whole &#8220;Admin API&#8221; section
                    </li>
                    <li>
                      enable &#8220;Storefront API&#8221; and check on all &#8220;Read&#8221; permissions
                    </li>
                    <li>
                      save your app
                    </li>
                  </ol>
                </li>
                
                <li>
                  copy your app&#8217;s &#8220;Storefront access token&#8221; (NOT TO BE CONFUSED with the &#8220;API Token&#8221;) and use this as your <code>shopify-storefront-access-token</code>
                </li>
              </ul>
            </li>
          </ul>
          
          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--customize-shoppers-appearance-with-css" class="anchor" aria-hidden="true" href="#-customize-shoppers-appearance-with-css"></a>šŸ’… customize shopper&#8217;s appearance with css
          </h2>
          
          <ul dir="auto">
            <li>
              <strong>shopper looks very plain and ugly by default</strong><br /> that&#8217;s because it&#8217;s designed to be customized.<br /> shopper only comes with bare-bones layout styles, so it&#8217;s as easy as possible to customize to match your store
            </li>
            <li>
              <strong>shopper&#8217;s web components render to light-dom</strong><br /> this allows complete css customization
            </li>
            <li>
              <strong>basic css knowledge is required for visual customizations</strong><br /> the recommended workflow, is to right-click inspect-element anything you want to customize, look at it&#8217;s element names and class names, and then write some CSS rules on your page.<br /> you have to be a bit of a nerd to get this done.<br /> we&#8217;re open to somebody writing some standard themes so people can avoid this step in the future
            </li>
          </ul>
          
          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--under-the-hood" class="anchor" aria-hidden="true" href="#-under-the-hood"></a>šŸ‘©ā€šŸ”§ under the hood
          </h2>
          
          <ul dir="auto">
            <li>
              published as an npm package <code>shopper</code>
            </li>
            <li>
              written in typescript
            </li>
            <li>
              es modules
            </li>
            <li>
              universally-compatible web components
            </li>
            <li>
              only makes network requests to shopify, and to <a rel="nofollow noopener" target="_blank" href="https://www.bankofcanada.ca/valet/docs">https://www.bankofcanada.ca/valet/docs</a> to fetch exchange rates via crnc
            </li>
            <li>
              saves cart data to <code>localStorage</code> to keep track of your cart between page loads
            </li>
          </ul>
          
          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--made-with-open-source-love-just-for-you" class="anchor" aria-hidden="true" href="#-made-with-open-source-love-just-for-you"></a>šŸ’– made with open source love, just for you
          </h2>
          
          <ul dir="auto">
            <li>
              please file issues and collaborate šŸ»
            </li>
            <li>
              we should make some example css themes that look good so people don&#8217;t have to customize the css
            </li>
            <li>
              we should publish an optimized rollup build for end-use (not suitable for consumption from apps with their own build)
            </li>
          </ul>