npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dabolus/shop-cart

v1.2.3

Published

ShopCart is a custom cart designed to replace the official Shopify Buy Button implementation

Downloads

101

Readme

ShopCart

ShopCart is a custom cart designed to replace the official Shopify Buy Button implementation, giving developers the possibility to fully customize the cart experience for their users.

PLEASE NOTE This product is not associated nor endorsed by Shopify. ShopCart uses undocumented Shopify APIs that are used by the official Buy Button implementation. Shopify can decide to drop the support for these any time without prior notice.

Install

ShopCart source code and builds can be downloaded from github or via npm.

npm install shop-cart

Include ShopCart in your web page as a script before the initialization script. It's recommended to place both these scripts at the end of your page content.

<script type="text/javascript" src="./dist/index.min.js"></script>
<script type="text/javascript">
  var config = {
    ...
  };
  var cart = new ShopCart.CartController(config);
</script>

Library versions

Library version files are located in the ./dist folder of the project.

In order to work, ShopCart requires store to save cart data. If you already have store imported in your website or if you want to use a specific version for the library, you can do so by using:

index.js

Unminified ShopCart library only

index.min.js

Minified ShopCart library only

Otherwise, you can use the following builds that include the store library:

index.store.js

Unminified library including store library

index.store.min.js

Minified library including store library

Configuration

Some features of ShopCart can be configured to make it work properly with your store.

{
  "store": {
    "name": "YOUR_STORE_NAME",
    "url": "YOUR_SHOPIFY_STORE_URL"
  },
  "currencies": [
    {
      "name":"United States Dollar",
      "code": "USD",
      "symbol": "$",
      "label": "USD",
      "default": true
    }
  ],
  "image": {
    "basePath":"IMAGE_BASE_PATH",
    "lazyload": true
  },
  "products": [
    {
      "id": "PRODUCT_UNIQUE_ID",
      "name": "PRODUCT_NAME",
      "description": "PRODUCT_DESCRIPTION",
      "price": PRODUCT_PRICE,
      "image": {
        "url": "PRODUCT_IMAGE"
      },
      "variants": [
        {
          "name": "PRODUCT_VARIANT_NAME",
          "upc": PRODUCT_VARIANT_UPC,
          "sku": "PRODUCT_VARIANT_SKU",
          "image": {
            "url": "PRODUCT_VARIANT_IMAGE"
          }
        },
        ...
      ]
    }
  ]
}

API

ShopCart.getItem(PRODUCT_VARIANT_UPC)

Returns the item with the given UPC. If the UPC is not listed in the config.products array, null value is returned.

ShopCart.setItem(PRODUCT_VARIANT_UPC)

Adds the item with the given UPC to the cart. If the item is already in the cart, the quantity is incremented. Returns the number of items in the cart for the given UPC. If the UPC is not listed in the config.products array, null value is returned.

ShopCart.removeItem(PRODUCT_VARIANT_UPC)

Removes the item with the given UPC to the cart. If the item is already in the cart, the quantity is decremented. Returns the number of items in the cart for the given UPC. If the UPC is not listed in the config.products array, null value is returned.

ShopCart.getCheckoutUrl()

Returns the checkout url for the current cart, to which redirect the user for check out the cart and complete the order.

ShopCart.openCart()

Refreshes total and quantity and set the class to open the cart.

Integration

The cart is adding classes to the document to be used for customizing the style

body.cart-ready

Attached to the body when the cart setup is ready.

body.cart-open

Attached to the body when the cart setup is open.

element.cart-quantity-notification.active
element.store-cart-area.active
element.store-cart-footer.active

When cart has at least one element, attach the class active to the elment with class cart-quantity-notification, store-cart-area and store-cart-footer.

element.store-cart.PRODUCT_UNIQUE_ID

The PRODUCT_ID associated to each product available is attached to each element with class store-cart.

Events

Actions on the cart will trigger custom events to which it's possible to subscribe.

Cart init started

window.addEventListener("shop-cart-init", function(e) {
  ...
});

Cart ready to be used

window.addEventListener("shop-cart-ready", function(e) {
  ...
});

Product added

window.addEventListener("shop-cart-add", function(e) {
  ...
  console.log(e.detail); // The field 'detail' contains the UPC of the product added
  ...
});

Product removed

window.addEventListener("shop-cart-remove", function(e) {
  ...
  console.log(e.detail); // The field 'detail' contains the UPC of the product removed
  ...
});

Cart opened

window.addEventListener("shop-cart-open", function(e) {
  ...
});

Support

Shop cart should work properly with major modern browsers and has been tested with the following:

  • Chrome 63
  • Firefox 57
  • Safari 11
  • Opera 49
  • Edge 38
  • IE 9

Example

Empatica Store

Edit and build files

If you want to edit and/or build the source code, you can do so by running

cd ${SHOP_CART_DIRECTORY}
npm install
./node_modules/.bin/gulp build

Build files are located in the ./dist folder of the project.