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.9.13 to 1.9.14

18

package.json
{
"name": "commercelayer",
"version": "1.9.13",
"version": "1.9.14",
"description": "The Official Commerce Layer JS library",

@@ -22,2 +22,8 @@ "main": "./src/main.js",

"author": "Filippo Conforti",
"contributors": [
{
"name": "Alessandro Casazza",
"email": "alessandro@commercelayer.io"
}
],
"license": "MIT",

@@ -29,10 +35,10 @@ "bugs": {

"dependencies": {
"@commercelayer/sdk": "^1.6.2",
"js-cookie": "^2.2.0",
"lodash": "^4.17.11"
"@commercelayer/sdk": "^1.6.3",
"js-cookie": "^2.2.1",
"lodash": "^4.17.15"
},
"devDependencies": {
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1"
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
}
}

@@ -1,51 +0,51 @@

const config = require("./config");
const utils = require("./utils");
const ui = require("./ui");
const clsdk = require("@commercelayer/sdk");
const config = require('./config')
const utils = require('./utils')
const ui = require('./ui')
const clsdk = require('@commercelayer/sdk')
module.exports = {
getPrices: function() {
let prices = document.querySelectorAll(".clayer-price");
let prices = document.querySelectorAll('.clayer-price')
if (prices.length > 0) {
let skuCodes = [];
let skuCodes = []
prices.forEach(function(price) {
skuCodes.push(price.dataset.skuCode);
});
skuCodes.push(price.dataset.skuCode)
})
let qf = new clsdk.query.QueryFilter()
.filter("codes", skuCodes.join(","))
.include("prices")
.pageSize(25);
.filter('codes', skuCodes.join(','))
.include('prices')
.pageSize(25)
clsdk.listSkus(qf.build()).then(data => {
let skuAttributes = [
"id",
"code",
"prices.formatted_amount",
"prices.formatted_compare_at_amount",
"prices.amount_cents",
"prices.compare_at_amount_cents"
];
'id',
'code',
'prices.formatted_amount',
'prices.formatted_compare_at_amount',
'prices.amount_cents',
'prices.compare_at_amount_cents'
]
ui.updatePrices(data.get(skuAttributes));
ui.updatePrices(data.get(skuAttributes))
let pageCount = data.dataset.meta.page_count;
let pageCount = data.dataset.meta.page_count
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p);
qf.pageNumber(p)
clsdk
.listSkus(qf)
.then(data => ui.updatePrices(data.get(skuAttributes)));
.then(data => ui.updatePrices(data.get(skuAttributes)))
}
}
document.dispatchEvent(new Event("clayer-prices-ready"));
document.dispatchEvent(new Event('clayer-prices-ready'))
if (data.get(skuAttributes).length === 0) {
document.dispatchEvent(new Event("clayer-skus-empty"));
document.dispatchEvent(new Event('clayer-skus-empty'))
}
});
})
}

@@ -55,32 +55,32 @@ },

getVariants: function() {
let variants = document.querySelectorAll(".clayer-variant");
let variants = document.querySelectorAll('.clayer-variant')
if (variants.length > 0) {
let skuCodes = [];
let skuCodes = []
variants.forEach(function(variant) {
skuCodes.push(variant.dataset.skuCode);
});
skuCodes.push(variant.dataset.skuCode)
})
let qf = new clsdk.query.QueryFilter()
.filter("codes", skuCodes.join(","))
.pageSize(25);
.filter('codes', skuCodes.join(','))
.pageSize(25)
let skuAttributes = ["id", "code"];
let skuAttributes = ['id', 'code']
clsdk.listSkus(qf.build()).then(data => {
ui.updateVariants(data.get(skuAttributes), true);
ui.updateVariants(data.get(skuAttributes), true)
let pageCount = data.dataset.meta.page_count;
let pageCount = data.dataset.meta.page_count
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p);
qf.pageNumber(p)
clsdk
.listSkus(qf)
.then(data => ui.updateVariants(data.get(skuAttributes), false));
.then(data => ui.updateVariants(data.get(skuAttributes), false))
}
}
document.dispatchEvent(new Event("clayer-variants-ready"));
});
document.dispatchEvent(new Event('clayer-variants-ready'))
})
}

@@ -91,25 +91,25 @@ },

let variantQuantity = document.querySelectorAll(
".clayer-add-to-bag-quantity"
);
'.clayer-add-to-bag-quantity'
)
if (variantQuantity.length > 0) {
let skuCodes = [];
let skuCodes = []
variantQuantity.forEach(function(variant) {
skuCodes.push(variant.dataset.skuCode);
});
skuCodes.push(variant.dataset.skuCode)
})
let qf = new clsdk.query.QueryFilter()
.filter("codes", skuCodes.join(","))
.pageSize(25);
.filter('codes', skuCodes.join(','))
.pageSize(25)
let skuAttributes = ["id", "code"];
let skuAttributes = ['id', 'code']
clsdk.listSkus(qf.build()).then(data => {
ui.updateVariantsQuantity(data.get(skuAttributes), true);
ui.updateVariantsQuantity(data.get(skuAttributes), true)
let pageCount = data.dataset.meta.page_count;
let pageCount = data.dataset.meta.page_count
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p);
qf.pageNumber(p)
clsdk

@@ -119,7 +119,7 @@ .listSkus(qf)

ui.updateVariantsQuantity(data.get(skuAttributes), false)
);
)
}
}
document.dispatchEvent(new Event("clayer-variants-quantity-ready"));
});
document.dispatchEvent(new Event('clayer-variants-quantity-ready'))
})
}

@@ -129,32 +129,32 @@ },

getAddToBags: function() {
let addToBags = document.querySelectorAll(".clayer-add-to-bag");
let addToBags = document.querySelectorAll('.clayer-add-to-bag')
if (addToBags.length > 0) {
let skuCodes = [];
let skuCodes = []
addToBags.forEach(function(addToBag) {
skuCodes.push(addToBag.dataset.skuCode);
});
skuCodes.push(addToBag.dataset.skuCode)
})
let qf = new clsdk.query.QueryFilter()
.filter("codes", skuCodes.join(","))
.pageSize(25);
.filter('codes', skuCodes.join(','))
.pageSize(25)
let skuAttributes = ["id", "code"];
let skuAttributes = ['id', 'code']
clsdk.listSkus(qf.build()).then(data => {
ui.updateAddToBags(data.get(skuAttributes));
ui.updateAddToBags(data.get(skuAttributes))
let pageCount = data.dataset.meta.page_count;
let pageCount = data.dataset.meta.page_count
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p);
qf.pageNumber(p)
clsdk
.listSkus(qf)
.then(data => ui.updateAddToBags(data.get(skuAttributes)));
.then(data => ui.updateAddToBags(data.get(skuAttributes)))
}
}
document.dispatchEvent(new Event("clayer-add-to-bags-ready"));
});
document.dispatchEvent(new Event('clayer-add-to-bags-ready'))
})
}

@@ -173,22 +173,22 @@ },

) {
console.log("addToBagQuantityId :", addToBagQuantityId);
let qf = new clsdk.query.QueryFilter().include("prices").pageSize(25);
console.log('addToBagQuantityId :', addToBagQuantityId)
let qf = new clsdk.query.QueryFilter().include('prices').pageSize(25)
clsdk.retrieveSku(skuId, qf.build()).then(data => {
let skuAttributes = [
"id",
"code",
"inventory",
"prices.formatted_amount",
"prices.formatted_compare_at_amount",
"prices.amount_cents",
"prices.compare_at_amount_cents"
];
'id',
'code',
'inventory',
'prices.formatted_amount',
'prices.formatted_compare_at_amount',
'prices.amount_cents',
'prices.compare_at_amount_cents'
]
let sku = data.get(skuAttributes);
ui.updatePrice(sku, priceContainerId);
let sku = data.get(skuAttributes)
ui.updatePrice(sku, priceContainerId)
ui.updateAvailabilityMessage(
sku.inventory,
availabilityMessageContainerId
);
)
if (sku.inventory.available) {

@@ -202,3 +202,3 @@ ui.updateAddToBagSKU(

addToBagQuantityId
);
)
ui.updateAddVariantQuantitySKU(

@@ -211,13 +211,13 @@ skuId,

addToBagQuantityId
);
)
// TODO: enable quantity
ui.enableAddToBag(addToBagId);
ui.enableAddVariantQuantity(addToBagQuantityId);
ui.enableAddToBag(addToBagId)
ui.enableAddVariantQuantity(addToBagQuantityId)
} else {
// TODO: disable quantity
ui.disableAddToBag(addToBagId);
ui.disableAddVariantQuantity(addToBagQuantityId);
ui.disableAddToBag(addToBagId)
ui.disableAddVariantQuantity(addToBagQuantityId)
}
document.dispatchEvent(new Event("clayer-variant-selected"));
});
document.dispatchEvent(new Event('clayer-variant-selected'))
})
},

@@ -228,3 +228,3 @@

.createOrder({
type: "orders",
type: 'orders',
shipping_country_code_lock: config.countryCode,

@@ -238,28 +238,38 @@ language_code: config.languageCode,

.then(response => {
utils.setOrderToken(response.dataset.data.attributes.token);
return response.dataset.data;
});
utils.setOrderToken(response.dataset.data.id)
return response.dataset.data
})
},
getOrder: function() {
api = this;
api = this
let qf = new clsdk.query.QueryFilter();
let qf = new clsdk.query.QueryFilter()
qf.include("line_items")
.filter("token", utils.getOrderToken())
.pageSize(25);
qf.include('line_items')
return clsdk.retrieveOrder(utils.getOrderToken(), qf).then(response => {
if (response.dataset.data.attributes) {
api.updateShoppingBagItems(response)
ui.updateShoppingBagSummary(response.dataset.data)
ui.updateShoppingBagCheckout(response)
if (response.dataset.data.attributes.skus_count === 0) {
ui.clearShoppingBag()
}
document.dispatchEvent(new Event('clayer-order-ready'))
return response.dataset.data
}
})
return clsdk.listOrders(qf).then(function(response) {
if (response.get(["line_items"]).length > 0) {
api.updateShoppingBagItems(response);
ui.updateShoppingBagSummary(response.dataset.data[0]);
ui.updateShoppingBagCheckout(response);
if (response.get("skus_count") == 0) {
ui.clearShoppingBag();
if (response.get(['line_items']).length > 0) {
api.updateShoppingBagItems(response)
ui.updateShoppingBagSummary(response.dataset.data[0])
ui.updateShoppingBagCheckout(response)
if (response.get('skus_count') == 0) {
ui.clearShoppingBag()
}
document.dispatchEvent(new Event("clayer-order-ready"));
return response.dataset.data[0];
document.dispatchEvent(new Event('clayer-order-ready'))
return response.dataset.data[0]
}
});
})
},

@@ -270,7 +280,7 @@

this.getOrder().then(function(order) {
if (!order || order.attributes.status == "placed") {
utils.deleteOrderToken();
ui.clearShoppingBag();
if (!order || order.attributes.status == 'placed') {
utils.deleteOrderToken()
ui.clearShoppingBag()
}
});
})
}

@@ -288,3 +298,3 @@ },

let lineItemData = {
type: "line_items",
type: 'line_items',
attributes: {

@@ -297,3 +307,3 @@ quantity,

data: {
type: "orders",
type: 'orders',
id: orderId

@@ -304,3 +314,3 @@ }

data: {
type: "skus",
type: 'skus',
id: skuId

@@ -310,8 +320,8 @@ }

}
};
}
if (skuName) lineItemData.attributes.name = skuName;
if (skuReference) lineItemData.attributes.reference = skuReference;
if (skuImageUrl) lineItemData.attributes.image_url = skuImageUrl;
if (quantity) lineItemData.attributes.quantity = quantity;
if (skuName) lineItemData.attributes.name = skuName
if (skuReference) lineItemData.attributes.reference = skuReference
if (skuImageUrl) lineItemData.attributes.image_url = skuImageUrl
if (quantity) lineItemData.attributes.quantity = quantity

@@ -323,5 +333,5 @@ return clsdk

.then(function(response) {
document.dispatchEvent(new Event("clayer-line-item-created"));
return response;
});
document.dispatchEvent(new Event('clayer-line-item-created'))
return response
})
},

@@ -331,5 +341,5 @@

return clsdk.deleteLineItem(lineItemId).then(function(response) {
document.dispatchEvent(new Event("clayer-line-item-deleted"));
return response;
});
document.dispatchEvent(new Event('clayer-line-item-deleted'))
return response
})
},

@@ -341,3 +351,3 @@

data: {
type: "line_items",
type: 'line_items',
id: lineItemId,

@@ -348,5 +358,5 @@ attributes: attributes

.then(function(response) {
document.dispatchEvent(new Event("clayer-line-item-updated"));
return response;
});
document.dispatchEvent(new Event('clayer-line-item-updated'))
return response
})
},

@@ -359,7 +369,7 @@

) {
api = this;
api = this
api
.updateLineItem(lineItemId, { quantity: quantity })
.then(function() {
api.getOrder();
api.getOrder()
})

@@ -371,44 +381,44 @@ .catch(function(error) {

if (availabilityMessageContainer) {
ui.displayUnavailableMessage(availabilityMessageContainer);
ui.displayUnavailableMessage(availabilityMessageContainer)
}
break;
break
}
}
});
})
},
updateShoppingBagItems: function(order) {
api = this;
api = this
let shoppingBagItemsContainer = document.querySelector(
"#clayer-shopping-bag-items-container"
);
'#clayer-shopping-bag-items-container'
)
if (shoppingBagItemsContainer) {
normalized_order = 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.reference",
"line_items.quantity",
"line_items.formatted_unit_amount",
"line_items.formatted_total_amount"
])[0];
'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.reference',
'line_items.quantity',
'line_items.formatted_unit_amount',
'line_items.formatted_total_amount'
])
if (normalized_order.line_items) {
shoppingBagItemsContainer.innerHTML = "";
shoppingBagItemsContainer.innerHTML = ''
for (i = 0; i < normalized_order.line_items.length; i++) {
line_item = normalized_order.line_items[i];
line_item = normalized_order.line_items[i]
if (line_item.item_type == "skus") {
if (line_item.item_type == 'skus') {
let shoppingBagItemTemplate = document.querySelector(
"#clayer-shopping-bag-item-template"
);
'#clayer-shopping-bag-item-template'
)

@@ -418,10 +428,10 @@ if (shoppingBagItemTemplate) {

shoppingBagItemTemplate
);
)
// image
let shoppingBagItemImage = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-image"
);
'.clayer-shopping-bag-item-image'
)
if (shoppingBagItemImage) {
shoppingBagItemImage.src = line_item.image_url;
shoppingBagItemImage.src = line_item.image_url
}

@@ -431,6 +441,6 @@

let shoppingBagItemName = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-name"
);
'.clayer-shopping-bag-item-name'
)
if (shoppingBagItemName) {
shoppingBagItemName.innerHTML = line_item.name;
shoppingBagItemName.innerHTML = line_item.name
}

@@ -440,6 +450,6 @@

let shoppingBagItemReference = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-reference"
);
'.clayer-shopping-bag-item-reference'
)
if (shoppingBagItemReference) {
shoppingBagItemReference.innerHTML = line_item.reference;
shoppingBagItemReference.innerHTML = line_item.reference
}

@@ -449,23 +459,23 @@

let shoppingBagItemQtyContainer = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-qty-container"
);
'.clayer-shopping-bag-item-qty-container'
)
if (shoppingBagItemQtyContainer) {
let availabilityMessageContainer = shoppingBagItemQtyContainer.querySelector(
".clayer-shopping-bag-item-availability-message-container"
);
'.clayer-shopping-bag-item-availability-message-container'
)
let qtySelect = document.createElement("select");
qtySelect.dataset.lineItemId = line_item.id;
let qtySelect = document.createElement('select')
qtySelect.dataset.lineItemId = line_item.id
for (qty = 1; qty <= 50; qty++) {
let option = document.createElement("option");
option.value = qty;
option.text = qty;
let option = document.createElement('option')
option.value = qty
option.text = qty
if (qty == line_item.quantity) {
option.selected = true;
option.selected = true
}
qtySelect.appendChild(option);
qtySelect.appendChild(option)
}
qtySelect.addEventListener("change", function(event) {
qtySelect.addEventListener('change', function(event) {
api.updateLineItemQty(

@@ -475,8 +485,8 @@ this.dataset.lineItemId,

availabilityMessageContainer
);
});
)
})
shoppingBagItemQtyContainer.insertBefore(
qtySelect,
shoppingBagItemQtyContainer.firstChild
);
)
}

@@ -486,7 +496,7 @@

let shoppingBagItemUnitAmount = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-unit-amount"
);
'.clayer-shopping-bag-item-unit-amount'
)
if (shoppingBagItemUnitAmount) {
shoppingBagItemUnitAmount.innerHTML =
line_item.formatted_unit_amount;
line_item.formatted_unit_amount
}

@@ -496,7 +506,7 @@

let shoppingBagItemTotalAmount = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-total-amount"
);
'.clayer-shopping-bag-item-total-amount'
)
if (shoppingBagItemTotalAmount) {
shoppingBagItemTotalAmount.innerHTML =
line_item.formatted_total_amount;
line_item.formatted_total_amount
}

@@ -506,20 +516,20 @@

let shoppingBagItemRemove = shoppingBagItem.querySelector(
".clayer-shopping-bag-item-remove"
);
'.clayer-shopping-bag-item-remove'
)
if (shoppingBagItemRemove) {
shoppingBagItemRemove.dataset.lineItemId = line_item.id;
shoppingBagItemRemove.addEventListener("click", function(
shoppingBagItemRemove.dataset.lineItemId = line_item.id
shoppingBagItemRemove.addEventListener('click', function(
event
) {
event.preventDefault();
event.stopPropagation();
event.preventDefault()
event.stopPropagation()
api
.deleteLineItem(this.dataset.lineItemId)
.then(function(lineItem) {
api.getOrder();
});
});
api.getOrder()
})
})
}
shoppingBagItemsContainer.appendChild(shoppingBagItem);
shoppingBagItemsContainer.appendChild(shoppingBagItem)
}

@@ -531,2 +541,2 @@ }

}
};
}

@@ -1,8 +0,8 @@

const utils = require("./utils");
const normalize = require("json-api-normalize");
const utils = require('./utils')
const normalize = require('json-api-normalize')
function enableElement(element) {
if (element) {
element.removeAttribute("disabled");
element.classList.remove("disabled");
element.removeAttribute('disabled')
element.classList.remove('disabled')
}

@@ -13,4 +13,4 @@ }

if (element) {
element.setAttribute("disabled", "disabled");
element.classList.add("disabled");
element.setAttribute('disabled', 'disabled')
element.classList.add('disabled')
}

@@ -21,3 +21,3 @@ }

if (element) {
element.style.display = "block";
element.style.display = 'block'
}

@@ -28,3 +28,3 @@ }

if (element) {
element.style.display = "none";
element.style.display = 'none'
}

@@ -34,5 +34,5 @@ }

function setElementHTML(parent, selector, html) {
element = parent.querySelector(selector);
element = parent.querySelector(selector)
if (element) {
element.innerHTML = html;
element.innerHTML = html
}

@@ -43,7 +43,7 @@ }

let shoppingBagItemsCounts = document.querySelectorAll(
".clayer-shopping-bag-items-count"
);
'.clayer-shopping-bag-items-count'
)
shoppingBagItemsCounts.forEach(function(shoppingBagItemsCount) {
shoppingBagItemsCount.innerHTML = order.attributes.skus_count;
});
shoppingBagItemsCount.innerHTML = order.attributes.skus_count
})
}

@@ -53,8 +53,8 @@

let shoppingBagTotals = document.querySelectorAll(
".clayer-shopping-bag-total"
);
'.clayer-shopping-bag-total'
)
shoppingBagTotals.forEach(function(shoppingBagTotal) {
shoppingBagTotal.innerHTML =
order.attributes.formatted_total_amount_with_taxes;
});
order.attributes.formatted_total_amount_with_taxes
})
}

@@ -64,7 +64,7 @@

let shoppingBagSubtotals = document.querySelectorAll(
".clayer-shopping-bag-subtotal"
);
'.clayer-shopping-bag-subtotal'
)
shoppingBagSubtotals.forEach(function(shoppingBagSubtotal) {
shoppingBagSubtotal.innerHTML = order.attributes.formatted_subtotal_amount;
});
shoppingBagSubtotal.innerHTML = order.attributes.formatted_subtotal_amount
})
}

@@ -74,7 +74,7 @@

let shoppingBagShippings = document.querySelectorAll(
".clayer-shopping-bag-shipping"
);
'.clayer-shopping-bag-shipping'
)
shoppingBagShippings.forEach(function(shoppingBagShipping) {
shoppingBagShipping.innerHTML = order.attributes.formatted_shipping_amount;
});
shoppingBagShipping.innerHTML = order.attributes.formatted_shipping_amount
})
}

@@ -84,17 +84,15 @@

let shoppingBagPayments = document.querySelectorAll(
".clayer-shopping-bag-payment"
);
'.clayer-shopping-bag-payment'
)
shoppingBagPayments.forEach(function(shoppingBagPayment) {
shoppingBagPayment.innerHTML =
order.attributes.formatted_payment_method_amount;
});
order.attributes.formatted_payment_method_amount
})
}
function updateShoppingBagTaxes(order) {
let shoppingBagTaxes = document.querySelectorAll(
".clayer-shopping-bag-taxes"
);
let shoppingBagTaxes = document.querySelectorAll('.clayer-shopping-bag-taxes')
shoppingBagTaxes.forEach(function(shoppingBagTax) {
shoppingBagTax.innerHTML = order.attributes.formatted_total_tax_amount;
});
shoppingBagTax.innerHTML = order.attributes.formatted_total_tax_amount
})
}

@@ -104,7 +102,7 @@

let shoppingBagDiscounts = document.querySelectorAll(
".clayer-shopping-bag-discount"
);
'.clayer-shopping-bag-discount'
)
shoppingBagDiscounts.forEach(function(shoppingBagDiscount) {
shoppingBagDiscount.innerHTML = order.attributes.formatted_discount_amount;
});
shoppingBagDiscount.innerHTML = order.attributes.formatted_discount_amount
})
}

@@ -114,9 +112,9 @@

updatePrice(sku, priceContainerId) {
priceContainer = document.querySelector(`#${priceContainerId}`);
priceContainer = document.querySelector(`#${priceContainerId}`)
if (priceContainer) {
priceAmount = priceContainer.querySelector(".amount");
priceAmount = priceContainer.querySelector('.amount')
if (priceAmount) {
priceAmount.innerHTML = sku.prices[0].formatted_amount;
priceAmount.innerHTML = sku.prices[0].formatted_amount
}
priceCompareAmount = priceContainer.querySelector(".compare-at-amount");
priceCompareAmount = priceContainer.querySelector('.compare-at-amount')
if (priceCompareAmount) {

@@ -127,3 +125,3 @@ if (

priceCompareAmount.innerHTML =
sku.prices[0].formatted_compare_at_amount;
sku.prices[0].formatted_compare_at_amount
}

@@ -137,9 +135,9 @@ }

'[data-sku-code="' + sku.code + '"] > .amount'
);
)
priceAmounts.forEach(function(priceAmount) {
priceAmount.innerHTML = sku.prices[0].formatted_amount;
});
priceAmount.innerHTML = sku.prices[0].formatted_amount
})
priceCompareAmounts = document.querySelectorAll(
'[data-sku-code="' + sku.code + '"] > .compare-at-amount'
);
)
priceCompareAmounts.forEach(function(priceCompareAmount) {

@@ -150,13 +148,13 @@ if (

priceCompareAmount.innerHTML =
sku.prices[0].formatted_compare_at_amount;
sku.prices[0].formatted_compare_at_amount
}
});
});
})
})
},
updateVariants: function(skus, clear) {
if (clear === true) {
let allVariants = document.querySelectorAll(".clayer-variant");
let allVariants = document.querySelectorAll('.clayer-variant')
allVariants.forEach(function(variant) {
disableElement(variant);
});
disableElement(variant)
})
}

@@ -166,26 +164,26 @@ skus.forEach(function(sku) {

'.clayer-variant[data-sku-code="' + sku.code + '"]'
);
)
variants.forEach(function(variant) {
variant.value = sku.id;
enableElement(variant);
});
});
variant.value = sku.id
enableElement(variant)
})
})
},
updateVariantsQuantity: function(skus) {
console.log("skus :", skus);
console.log('skus :', skus)
let allAddVariantQuantity = document.querySelectorAll(
".clayer-add-to-bag-quantity"
);
'.clayer-add-to-bag-quantity'
)
allAddVariantQuantity.forEach(function(addVariantQuantity) {
disableElement(addVariantQuantity);
});
disableElement(addVariantQuantity)
})
skus.forEach(function(sku) {
let addVariantsQuantity = document.querySelectorAll(
'.clayer-add-to-bag-quantity[data-sku-code="' + sku.code + '"]'
);
)
addVariantsQuantity.forEach(function(addVariantQuantity) {
addVariantQuantity.dataset.skuId = sku.id;
enableElement(addVariantQuantity);
});
});
addVariantQuantity.dataset.skuId = sku.id
enableElement(addVariantQuantity)
})
})
},

@@ -200,11 +198,11 @@ updateAddVariantQuantitySKU: function(

) {
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`);
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`)
if (addVariantQuantity) {
addVariantQuantity.dataset.skuId = skuId;
addVariantQuantity.value = 1;
addVariantQuantity.min = 1;
if (skuName) addVariantQuantity.dataset.skuName = skuName;
if (skuReference) addVariantQuantity.dataset.skuReference = skuReference;
if (skuImageUrl) addVariantQuantity.dataset.skuImageUrl = skuImageUrl;
if (skuMaxQuantity) addVariantQuantity.max = skuMaxQuantity;
addVariantQuantity.dataset.skuId = skuId
addVariantQuantity.value = 1
addVariantQuantity.min = 1
if (skuName) addVariantQuantity.dataset.skuName = skuName
if (skuReference) addVariantQuantity.dataset.skuReference = skuReference
if (skuImageUrl) addVariantQuantity.dataset.skuImageUrl = skuImageUrl
if (skuMaxQuantity) addVariantQuantity.max = skuMaxQuantity
}

@@ -214,15 +212,15 @@ },

updateAddToBags: function(skus) {
let allAddToBags = document.querySelectorAll(".clayer-add-to-bag");
let allAddToBags = document.querySelectorAll('.clayer-add-to-bag')
allAddToBags.forEach(function(addToBag) {
disableElement(addToBag);
});
disableElement(addToBag)
})
skus.forEach(function(sku) {
let addToBags = document.querySelectorAll(
'.clayer-add-to-bag[data-sku-code="' + sku.code + '"]'
);
)
addToBags.forEach(function(addToBag) {
addToBag.dataset.skuId = sku.id;
enableElement(addToBag);
});
});
addToBag.dataset.skuId = sku.id
enableElement(addToBag)
})
})
},

@@ -237,34 +235,34 @@ updateAddToBagSKU: function(

) {
let addToBag = document.querySelector(`#${addToBagId}`);
let addToBag = document.querySelector(`#${addToBagId}`)
if (addToBag) {
addToBag.dataset.skuId = skuId;
if (skuName) addToBag.dataset.skuName = skuName;
if (skuReference) addToBag.dataset.skuReference = skuReference;
if (skuImageUrl) addToBag.dataset.skuImageUrl = skuImageUrl;
addToBag.dataset.skuId = skuId
if (skuName) addToBag.dataset.skuName = skuName
if (skuReference) addToBag.dataset.skuReference = skuReference
if (skuImageUrl) addToBag.dataset.skuImageUrl = skuImageUrl
if (addToBagQuantityId)
addToBag.dataset.addToBagQuantityId = addToBagQuantityId;
addToBag.dataset.addToBagQuantityId = addToBagQuantityId
}
},
enableAddVariantQuantity: function(addToBagQuantityId) {
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`);
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`)
if (addVariantQuantity) {
enableElement(addVariantQuantity);
enableElement(addVariantQuantity)
}
},
disableAddVariantQuantity: function(addToBagQuantityId) {
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`);
let addVariantQuantity = document.querySelector(`#${addToBagQuantityId}`)
if (addVariantQuantity) {
disableElement(addVariantQuantity);
disableElement(addVariantQuantity)
}
},
enableAddToBag: function(addToBagId) {
let addToBag = document.querySelector(`#${addToBagId}`);
let addToBag = document.querySelector(`#${addToBagId}`)
if (addToBag) {
enableElement(addToBag);
enableElement(addToBag)
}
},
disableAddToBag: function(addToBagId) {
let addToBag = document.querySelector(`#${addToBagId}`);
let addToBag = document.querySelector(`#${addToBagId}`)
if (addToBag) {
disableElement(addToBag);
disableElement(addToBag)
}

@@ -278,9 +276,9 @@ },

`#${availabilityMessageContainerId}`
);
)
if (availabilityMessageContainer) {
let first_level = utils.getInventoryFirstAvailableLevel(inventory);
let first_level = utils.getInventoryFirstAvailableLevel(inventory)
if (first_level.quantity > 0) {
this.displayAvailableMessage(availabilityMessageContainer, first_level);
this.displayAvailableMessage(availabilityMessageContainer, first_level)
} else {
this.displayUnavailableMessage(availabilityMessageContainer);
this.displayUnavailableMessage(availabilityMessageContainer)
}

@@ -290,83 +288,83 @@ }

updateShoppingBagSummary: function(order) {
updateShoppingBagItemsCount(order);
updateShoppingBagTotal(order);
updateShoppingBagSubtotal(order);
updateShoppingBagShipping(order);
updateShoppingBagPayment(order);
updateShoppingBagTaxes(order);
updateShoppingBagDiscount(order);
updateShoppingBagItemsCount(order)
updateShoppingBagTotal(order)
updateShoppingBagSubtotal(order)
updateShoppingBagShipping(order)
updateShoppingBagPayment(order)
updateShoppingBagTaxes(order)
updateShoppingBagDiscount(order)
},
updateShoppingBagCheckout: function(order) {
let shoppingBagCheckouts = document.querySelectorAll(
".clayer-shopping-bag-checkout"
);
'.clayer-shopping-bag-checkout'
)
shoppingBagCheckouts.forEach(function(shoppingBagCheckout) {
normalized_order = order.get(["line_items.id", "checkout_url"])[0];
normalized_order = order.get(['line_items.id', 'checkout_url'])
if (normalized_order.line_items) {
enableElement(shoppingBagCheckout);
shoppingBagCheckout.href = normalized_order.checkout_url;
enableElement(shoppingBagCheckout)
shoppingBagCheckout.href = normalized_order.checkout_url
} else {
shoppingBagCheckout.href = "";
disableElement(shoppingBagCheckout);
shoppingBagCheckout.href = ''
disableElement(shoppingBagCheckout)
}
});
})
},
displayAvailableMessage: function(container, stockLevel) {
dlt = stockLevel.delivery_lead_times[0];
qty = stockLevel.quantity;
minDays = dlt.min.days;
maxDays = dlt.max.days;
minHours = dlt.min.hours;
maxHours = dlt.max.hours;
shippingMethodName = dlt.shipping_method.name;
shippingMethodPrice = dlt.shipping_method.formatted_price_amount;
dlt = stockLevel.delivery_lead_times[0]
qty = stockLevel.quantity
minDays = dlt.min.days
maxDays = dlt.max.days
minHours = dlt.min.hours
maxHours = dlt.max.hours
shippingMethodName = dlt.shipping_method.name
shippingMethodPrice = dlt.shipping_method.formatted_price_amount
if (container) {
let template = document.querySelector(
"#clayer-availability-message-available-template"
);
'#clayer-availability-message-available-template'
)
if (template) {
let element = utils.getElementFromTemplate(template);
let element = utils.getElementFromTemplate(template)
setElementHTML(
element,
".clayer-availability-message-available-qty",
'.clayer-availability-message-available-qty',
qty
);
)
setElementHTML(
element,
".clayer-availability-message-available-min-days",
'.clayer-availability-message-available-min-days',
minDays
);
)
setElementHTML(
element,
".clayer-availability-message-available-max-days",
'.clayer-availability-message-available-max-days',
maxDays
);
)
setElementHTML(
element,
".clayer-availability-message-available-min-hours",
'.clayer-availability-message-available-min-hours',
minHours
);
)
setElementHTML(
element,
".clayer-availability-message-available-max-hours",
'.clayer-availability-message-available-max-hours',
maxHours
);
)
setElementHTML(
element,
".clayer-availability-message-available-shipping-method-name",
'.clayer-availability-message-available-shipping-method-name',
shippingMethodName
);
)
setElementHTML(
element,
".clayer-availability-message-available-shipping-method-price",
'.clayer-availability-message-available-shipping-method-price',
shippingMethodPrice
);
)
container.innerHTML = "";
container.appendChild(element);
displayElement(container);
container.innerHTML = ''
container.appendChild(element)
displayElement(container)
}

@@ -378,9 +376,9 @@ }

let template = document.querySelector(
"#clayer-availability-message-unavailable-template"
);
'#clayer-availability-message-unavailable-template'
)
if (template) {
let element = utils.getElementFromTemplate(template);
container.innerHTML = "";
container.appendChild(element);
displayElement(container);
let element = utils.getElementFromTemplate(template)
container.innerHTML = ''
container.appendChild(element)
displayElement(container)
}

@@ -391,10 +389,10 @@ }

let shoppingBagContainer = document.querySelector(
"#clayer-shopping-bag-container"
);
'#clayer-shopping-bag-container'
)
if (shoppingBagContainer) {
shoppingBagContainer.classList.toggle("open");
shoppingBagContainer.classList.toggle('open')
}
let main = document.querySelector("#clayer-main");
let main = document.querySelector('#clayer-main')
if (main) {
main.classList.toggle("open");
main.classList.toggle('open')
}

@@ -404,16 +402,16 @@ },

let shoppingBagContainer = document.querySelector(
"#clayer-shopping-bag-container"
);
'#clayer-shopping-bag-container'
)
if (shoppingBagContainer) {
shoppingBagContainer.classList.add("open");
shoppingBagContainer.classList.add('open')
}
let main = document.querySelector("#clayer-main");
let main = document.querySelector('#clayer-main')
if (main) {
main.classList.remove("open");
main.classList.remove('open')
}
},
clearShoppingBag: function() {
if (document.querySelector("#clayer-shopping-bag-items-container")) {
document.querySelector("#clayer-shopping-bag-items-container").innerHTML =
"";
if (document.querySelector('#clayer-shopping-bag-items-container')) {
document.querySelector('#clayer-shopping-bag-items-container').innerHTML =
''
}

@@ -423,8 +421,8 @@ },

let allAvailabilityMessageContainers = document.querySelectorAll(
".clayer-availability-message-container"
);
'.clayer-availability-message-container'
)
allAvailabilityMessageContainers.forEach(function(container) {
hideElement(container);
});
hideElement(container)
})
}
};
}
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