Skip to content

Commit

Permalink
BIG-16042 AddToCart Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
haubc committed May 12, 2015
1 parent 99f1869 commit 915b1b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
8 changes: 8 additions & 0 deletions src/remote/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import RemoteBC from './remote';

export default class Cart extends RemoteBC
{
/**
* Add item to cart with options (variants)
*
* @param {Number} productId
* @param {Number} qty
* @param {Object} options
* @param {Function} callback
*/
itemAdd(productId, qty, options, callback) {
let payload = {
product_id: productId,
Expand Down
37 changes: 4 additions & 33 deletions src/remote/product-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,14 @@ export default class RemoteProductAttributes extends RemoteBC

/**
*
* @param jQuery $container
* @returns array
*/
getOptionValues($container) {
// What does this query mean?
//
// :input:radio:checked
// Get all radios that are checked (since they are grouped together by name).
// If the query is just :input alone, it will return all radios (even the ones that aren't selected).
//
// :input:not(:radio)
// This is to retrieve all text, hidden, dropdown fields that don't have "groups".
let $optionValues = $container.find(':input:radio:checked, :input:not(:radio)'),
params = {};

// iterate over values
$optionValues.each((index, ele) => {
let $ele = $(ele),
name = $ele.attr('name'),
val = $ele.val();

params[name] = val;
});

return params;
}

/**
*
* @param jQuery $container
* @param productId
* @param {Object} options
* @param {Number} productId
* @param callback
*/
optionChange($container, productId, callback)
optionChange(options, productId, callback)
{
let url = this.endPoint + productId,
params = this.getOptionValues($container);
params = options;

this.makeRequest(url, 'POST', params, callback);
}
Expand Down

0 comments on commit 915b1b8

Please sign in to comment.