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

ember-cart

v0.1.0

Published

Shopping cart primitives for Ember applications

Downloads

10

Readme

ember-cart

Build Status

About

Shopping cart primitives for Ember applications

Installing

ember install ember-cart

Looking for help?

If it is a bug please open an issue on GitHub.

Usage

ember-cart manages the adding, quantity editing, removal, and eventual payment processing of shopping cart items.

The primitives provided are intended to give a boilerplate base to work from. Customizing the templates is always a good place to start.

Components

  • {{cart-items}}

Provides a list of the shopping cart. Each line item is a {{cart-item}}. Shows the total cost of all the items in the cart.

  • {{cart-item}}

The line-item for each item type in the cart. Adding more than one of the same type will increase the quantity. Also handles removal of the item from the cart.

  • {{cart-counter}}

A counter that displays the current number of unique items in the cart.

this.cart

this.cart is injected into Controllers and Components. If you want to add an item to the cart you can create an action that does this.cart.pushItem:

actions: {
  pushItem(item) {
    this.cart.pushItem(item);
  }
}

Cart Items

You can push POJOs or Ember models into the cart. The basic information that an item requires is name and cost. ember-cart will handle checking to see if there is already an existing similar item in the cart. If there is, the quantity for that item is incremented. If not the item is added to the cart.

POJOs

POJOs pushed into the cart:

this.cart.pushItem({
  name: 'Doggie',
  cost: 400
});

Ember Models

You can push another model into the cart. However you should provide a toCartItem handler on that model to typecast that model to a CartItem.

// app/models/dog.js
export DS.Model.extend({
   toCartItem() {
      let CartItem = this.container.lookupFactory('model:cart-item');

      return CartItem.create({
        name: get(this, 'name'),
        cost: get(this, 'price')
      });
   }
});

Persisting to localStorage

If you want to persist the cart to localStorage so the items are available if the user comes back later you will need to set the localStorage flag in the Cart service to true:

// app/services/cart.js

import CartService from 'ember-cart/services/cart';

export default CartService.extend({
  localStorage: true
});

Please note: if you persist to localStorage you will have to handle the security around this. For example, if a user signs out of their account you will probably want to clear their cart:

actions: {
  signOut() {
    // signout handler
    this.cart.clearItems();
  }
}

Make sure to use clearItems() and not clear() as the former will ensure that localStorage is properly cleared out.

Avoiding quantity incrementation

You may only allow one of a specific type. To enforce the quantity doesn't increment you should set increment: false for the Cart Item:

this.cart.pushItem({
  name: 'Foo',
  price: 100,
  increment: false
});

Authors

We are very thankful for the many contributors

Versioning

This library follows Semantic Versioning

Want to help?

Please do! We are always looking to improve this library. Please see our Contribution Guidelines on how to properly submit issues and pull requests.

Legal

DockYard, Inc © 2015

@dockyard

Licensed under the MIT license