Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Shopping cart primitives for Ember applications
ember install ember-cart
If it is a bug please open an issue on GitHub.
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.
{{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);
}
}
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 pushed into the cart:
this.cart.pushItem({
name: 'Doggie',
cost: 400
});
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')
});
}
});
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.
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
});
We are very thankful for the many contributors
This library follows Semantic Versioning
Please do! We are always looking to improve this library. Please see our Contribution Guidelines on how to properly submit issues and pull requests.
DockYard, Inc © 2015
FAQs
Shopping cart primitives for Ember applications
We found that ember-cart demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.