Skip to content

Commit

Permalink
Merge pull request #13 from bigcommerce/BIG-16025-cart
Browse files Browse the repository at this point in the history
BIG-16025 Cart remote endpoints
  • Loading branch information
mcampa committed May 8, 2015
2 parents 7274617 + edee896 commit 4e4f405
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/events/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class CartEvents extends BaseEvents {
'[data-cart-remove]': {
eventName: 'cart-item-remove',
trigger: ['click']
},
'[data-cart-update]': {
eventName: 'cart-item-update',
trigger: ['click']
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
RemoteCountry,
RemoteProduct,
RemoteProductAttributes,
Search
Search,
Cart
} from './remote/index';

let internals = {
Expand Down Expand Up @@ -59,7 +60,8 @@ internals.remote = function () {
country: new RemoteCountry(),
productAttributes: new RemoteProductAttributes(),
product: new RemoteProduct(),
search: new Search()
search: new Search(),
cart: new Cart()
}
};

Expand Down
54 changes: 54 additions & 0 deletions src/remote/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import RemoteBC from './remote';

export default class Cart extends RemoteBC
{
/**
* Update cart item quantity
*
* @param {String} itemId
* @param {Number} qty
* @param {Function} callback
*/
itemUpdate(itemId, qty, callback) {
let items = [
{id: itemId, quantity: qty}
];
this.update(items, callback);
}

/**
* Remove cart item
*
* @param {String} itemId
* @param {Function} callback
*/
itemRemove(itemId, callback) {
let items = [
{id: itemId, quantity: 0}
];
this.update(items, callback);
}

/**
* Update cart items
*
* @param {Array} items
* @param {Function} callback
*/
update(items, callback) {
let payload = {
items: items
};
this.makeRequest('/cart/update', 'POST', payload, callback);
}

/**
* Get cart content
*
* @param {Object} params
* @param {Function} callback
*/
getContent(params, callback) {
this.makeRequest('/cart/content', 'GET', params, callback);
}
}
4 changes: 3 additions & 1 deletion src/remote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import RemoteCountry from './countries';
import RemoteProduct from './product';
import RemoteProductAttributes from './product-attributes';
import Search from './search';
import Cart from './cart';

export default RemoteBC;
export {
RemoteCountry,
RemoteProductAttributes,
RemoteProduct,
Search
Search,
Cart
};

0 comments on commit 4e4f405

Please sign in to comment.