Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commercelayer

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commercelayer - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

2

package.json
{
"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",

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc