commercelayer
Advanced tools
Comparing version 1.7.9 to 1.8.0
{ | ||
"name": "commercelayer", | ||
"version": "1.7.9", | ||
"version": "1.8.0", | ||
"description": "The Official Commerce Layer JS library", | ||
@@ -5,0 +5,0 @@ "main": "./src/main.js", |
@@ -57,4 +57,2 @@ const config = require('./config') | ||
ui.disableElement(document.querySelector(".clayer-add-to-bag")) | ||
let variants = document.querySelectorAll('.clayer-variant') | ||
@@ -80,15 +78,21 @@ | ||
variant = document.querySelector('.clayer-variant[data-sku-code="' + skus[i].code + '"]') | ||
let variant = document.querySelector('.clayer-variant[data-sku-code="' + skus[i].code + '"]') | ||
if (variant) { | ||
variant.value = skus[i].id | ||
ui.enableElement(variant) | ||
if (i == 0) { | ||
module.exports.selectVariant(variant) | ||
// if (i == 0) { | ||
// module.exports.selectVariant(variant) | ||
// } | ||
let addToBag = document.querySelector('.clayer-add-to-bag[data-sku-code="' + skus[i].code + '"]') | ||
if (addToBag) { | ||
addToBag.dataset.skuId = skus[i].id | ||
addToBag.dataset.skuName = variant.dataset.skuName | ||
} | ||
} | ||
} | ||
} | ||
); | ||
} | ||
@@ -95,0 +99,0 @@ }, |
@@ -26,25 +26,27 @@ const ui = require('./ui') | ||
setAddToShoppingBag: function() { | ||
let addToBag = document.querySelector(".clayer-add-to-bag") | ||
setAddToShoppingBagButtons: function() { | ||
let addToBagButtons = document.querySelectorAll(".clayer-add-to-bag") | ||
if (addToBag) { | ||
addToBag.addEventListener('click', function(event) { | ||
event.preventDefault() | ||
if (addToBagButtons.length > 0) { | ||
addToBagButtons.forEach(function (addToBag) { | ||
addToBag.addEventListener('click', function(event) { | ||
event.preventDefault() | ||
orderPromise = utils.getOrderToken() ? api.getOrder() : api.createOrder() | ||
orderPromise = utils.getOrderToken() ? api.getOrder() : api.createOrder() | ||
orderPromise.then(function(order){ | ||
orderPromise.then(function(order){ | ||
api.createLineItem(order.get('id')[0], addToBag.dataset.skuId, addToBag.dataset.skuName, addToBag.dataset.skuImageUrl).then(function(lineItem){ | ||
api.getOrder() | ||
ui.openShoppingBag() | ||
}) | ||
.catch(function(error) { | ||
if (error.response) { | ||
switch(error.response.status) { | ||
case 422: | ||
ui.displayUnavailableMessage() | ||
break | ||
api.createLineItem(order.get('id')[0], addToBag.dataset.skuId, addToBag.dataset.skuName, addToBag.dataset.skuImageUrl).then(function(lineItem){ | ||
api.getOrder() | ||
ui.openShoppingBag() | ||
}) | ||
.catch(function(error) { | ||
if (error.response) { | ||
switch(error.response.status) { | ||
case 422: | ||
ui.displayUnavailableMessage() | ||
break | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
@@ -51,0 +53,0 @@ }) |
@@ -25,3 +25,3 @@ function initCommercelayer() { | ||
listeners.setVariantSelect() | ||
listeners.setAddToShoppingBag() | ||
listeners.setAddToShoppingBagButtons() | ||
listeners.setShoppingBagToggle() | ||
@@ -28,0 +28,0 @@ api.refreshOrder() |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
300842
2046