commercelayer
Advanced tools
Comparing version 1.1.4 to 1.1.5
{ | ||
"name": "commercelayer", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "The official Commerce Layer JS library", | ||
@@ -5,0 +5,0 @@ "main": "./src/main.js", |
130
src/api.js
@@ -90,15 +90,2 @@ const elements = require('./elements') | ||
}, | ||
getOrder: function() { | ||
return axios | ||
.get('/api/orders?include=line_items&filter[token]=' + utils.getOrderToken()) | ||
.then(function(response) { | ||
if (response.data.data.length > 0) { | ||
ui.hideShoppingBagUnavailableMessage() | ||
ui.updateShoppingBagPreview(response.data.data[0]) | ||
ui.updateShoppingBagTable(response.data) | ||
ui.updateShoppingBagCheckout(response.data) | ||
return response.data.data[0] | ||
} | ||
}) | ||
}, | ||
createOrder: function() { | ||
@@ -197,4 +184,121 @@ return axios | ||
}) | ||
}, | ||
updateLineItemQty: function(lineItemId, quantity) { | ||
api = this | ||
api.updateLineItem(lineItemId, { quantity: quantity }).then(function(lineItem){ | ||
api.getOrder() | ||
}) | ||
.catch(function(error) { | ||
if (error.response) { | ||
switch(error.response.status) { | ||
case 422: | ||
ui.displayShoppingBagUnavailableMessage() | ||
break | ||
} | ||
} | ||
}) | ||
}, | ||
updateShoppingBagTable: function(order) { | ||
var api = this | ||
var $shoppingBagTable = elements.shoppingBagTable | ||
if ($shoppingBagTable) { | ||
var normalized_order = normalize(order).get([ | ||
'id', | ||
'formatted_subtotal_amount', | ||
'formatted_discount_amount', | ||
'formatted_shipping_amount', | ||
'formatted_payment_method_amount', | ||
'formatted_total_tax_amount', | ||
'formatted_total_amount_with_taxes', | ||
'line_items.id', | ||
'line_items.item_type', | ||
'line_items.image_url', | ||
'line_items.name', | ||
'line_items.quantity', | ||
'line_items.formatted_unit_amount', | ||
'line_items.formatted_total_amount' | ||
])[0] | ||
if (normalized_order.line_items) { | ||
$shoppingBagTable.innerHTML = '' | ||
for (var i = 0; i < normalized_order.line_items.length; i++) { | ||
var line_item = normalized_order.line_items[i] | ||
if (line_item.item_type == "skus") { | ||
var tableRow = document.createElement('tr') | ||
ui.addTableColImage(tableRow, line_item.image_url, 'shopping-bag-col-image') | ||
ui.addTableColText(tableRow, line_item.name, 'shopping-bag-col-name') | ||
var quantitySelect = document.createElement('select') | ||
quantitySelect.dataset.lineItemId = line_item.id | ||
for (var qty = 1; qty <= 10; qty++) { | ||
var option = document.createElement("option"); | ||
option.value = qty; | ||
option.text = qty; | ||
if (qty == line_item.quantity) { | ||
option.selected = true | ||
} | ||
quantitySelect.appendChild(option); | ||
} | ||
quantitySelect.addEventListener('change', function(event){ | ||
api.updateLineItemQty(this.dataset.lineItemId, this.value) | ||
}) | ||
ui.addTableColElement(tableRow, quantitySelect, 'shopping-bag-col-qty') | ||
ui.addTableColText(tableRow, line_item.formatted_total_amount, 'shopping-bag-col-total') | ||
// remove | ||
var removeLink = document.createElement('a') | ||
var removeLinkText = document.createTextNode('X') | ||
removeLink.appendChild(removeLinkText) | ||
removeLink.dataset.lineItemId = line_item.id | ||
removeLink.addEventListener('click', function(event){ | ||
event.preventDefault() | ||
this.parentElement.parentElement.remove() | ||
api.deleteLineItem(this.dataset.lineItemId).then(function(lineItem){ | ||
api.getOrder() | ||
}) | ||
}) | ||
ui.addTableColElement(tableRow, removeLink, 'shopping-bag-col-remove') | ||
$shoppingBagTable.appendChild(tableRow) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
getOrder: function() { | ||
var api = this | ||
return axios | ||
.get('/api/orders?include=line_items&filter[token]=' + utils.getOrderToken()) | ||
.then(function(response) { | ||
if (response.data.data.length > 0) { | ||
api.updateShoppingBagTable(response.data) | ||
ui.hideShoppingBagUnavailableMessage() | ||
ui.updateShoppingBagPreview(response.data.data[0]) | ||
ui.updateShoppingBagCheckout(response.data) | ||
return response.data.data[0] | ||
} | ||
}) | ||
} | ||
} |
@@ -1,30 +0,4 @@ | ||
const elements = require('./elements') | ||
const axios = require('axios') | ||
const auth = require('./auth') | ||
const normalize = require('json-api-normalize') | ||
const config = require('./config') | ||
const utils = require('./utils') | ||
const ui = require('./ui') | ||
const api = require('./api') | ||
const listeners = require('./listeners') | ||
// function updateLineItemQty(lineItemId, quantity) { | ||
// | ||
// api.updateLineItem(lineItemId, { quantity: quantity }).then(function(lineItem){ | ||
// api.getOrder() | ||
// }) | ||
// .catch(function(error) { | ||
// if (error.response) { | ||
// switch(error.response.status) { | ||
// case 422: | ||
// ui.displayShoppingBagUnavailableMessage() | ||
// break | ||
// } | ||
// } | ||
// }) | ||
// | ||
// } | ||
exports.init = function() { | ||
@@ -31,0 +5,0 @@ api.refreshOrder() |
@@ -95,87 +95,2 @@ const elements = require('./elements') | ||
}, | ||
updateShoppingBagTable: function(order) { | ||
var $shoppingBagTable = elements.shoppingBagTable | ||
if ($shoppingBagTable) { | ||
var normalized_order = normalize(order).get([ | ||
'id', | ||
'formatted_subtotal_amount', | ||
'formatted_discount_amount', | ||
'formatted_shipping_amount', | ||
'formatted_payment_method_amount', | ||
'formatted_total_tax_amount', | ||
'formatted_total_amount_with_taxes', | ||
'line_items.id', | ||
'line_items.item_type', | ||
'line_items.image_url', | ||
'line_items.name', | ||
'line_items.quantity', | ||
'line_items.formatted_unit_amount', | ||
'line_items.formatted_total_amount' | ||
])[0] | ||
if (normalized_order.line_items) { | ||
$shoppingBagTable.innerHTML = '' | ||
for (var i = 0; i < normalized_order.line_items.length; i++) { | ||
var line_item = normalized_order.line_items[i] | ||
if (line_item.item_type == "skus") { | ||
var tableRow = document.createElement('tr') | ||
this.addTableColImage(tableRow, line_item.image_url, 'shopping-bag-col-image') | ||
this.addTableColText(tableRow, line_item.name, 'shopping-bag-col-name') | ||
var quantitySelect = document.createElement('select') | ||
quantitySelect.dataset.lineItemId = line_item.id | ||
for (var qty = 1; qty <= 10; qty++) { | ||
var option = document.createElement("option"); | ||
option.value = qty; | ||
option.text = qty; | ||
if (qty == line_item.quantity) { | ||
option.selected = true | ||
} | ||
quantitySelect.appendChild(option); | ||
} | ||
quantitySelect.addEventListener('change', function(event){ | ||
updateLineItemQty(this.dataset.lineItemId, this.value) | ||
}) | ||
this.addTableColElement(tableRow, quantitySelect, 'shopping-bag-col-qty') | ||
this.addTableColText(tableRow, line_item.formatted_total_amount, 'shopping-bag-col-total') | ||
// remove | ||
var removeLink = document.createElement('a') | ||
var removeLinkText = document.createTextNode('X') | ||
removeLink.appendChild(removeLinkText) | ||
removeLink.dataset.lineItemId = line_item.id | ||
removeLink.addEventListener('click', function(event){ | ||
event.preventDefault() | ||
this.parentElement.parentElement.remove() | ||
// api.deleteLineItem(this.dataset.lineItemId).then(function(lineItem){ | ||
// api.getOrder() | ||
// }) | ||
}) | ||
this.addTableColElement(tableRow, removeLink, 'shopping-bag-col-remove') | ||
$shoppingBagTable.appendChild(tableRow) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
updateShoppingBagCheckout: function(order) { | ||
@@ -182,0 +97,0 @@ var $shoppingBagCheckout = elements.shoppingBagCheckout |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
22093
646