Skip to content

Commit

Permalink
Align cart addition methods
Browse files Browse the repository at this point in the history
  • Loading branch information
timowestnosto committed Jan 16, 2025
1 parent 91aa0b9 commit 14da5d5
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions view/frontend/web/js/recobuy.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ define([
};

// Product object must have fields productId and skuId {'productId': '123', 'skuId': '321'}
Recobuy.addSkuToCart = function (product, element) {
Recobuy.addSkuToCart = function (product, element, _quantity) {

const quantity = product.quantity || 1;
const quantity = product.quantity || _quantity || 1;
const url = document.querySelector("#nosto_addtocart_form").getAttribute("action");
const formKey = document.querySelector("#nosto_addtocart_form > input[name='form_key']").getAttribute("value");

Expand All @@ -86,7 +86,7 @@ define([
'sku': product.skuId,
},
success: function () {
Recobuy.sendCartEvent(element, product.productId)
Recobuy.sendCartEvent(element, product)
return resolve()
},
error: function () {
Expand All @@ -97,19 +97,20 @@ define([

};

Recobuy.sendCartEvent = function (element, productId) {
if (typeof element === 'object' && element) {
const slotId = this.resolveContextSlotId(element);
if (slotId) {
nostojs(function (api) {
// noinspection JSUnresolvedFunction
api.recommendedProductAddedToCart(productId, slotId);
});
}
Recobuy.sendCartEvent = function (element, product) {
const slotId = this.resolveContextSlotId(element);
if (slotId) {
nostojs(function (api) {
// noinspection JSUnresolvedFunction
api.reportAddToCart(product, slotId);
});
}
}

Recobuy.resolveContextSlotId = function (element) {
if (!element || typeof element === "string") {
return element;
}
const m = 20;
let n = 0;
let e = element;
Expand Down

0 comments on commit 14da5d5

Please sign in to comment.