PageSourceSearch

https://autotown.ru/local/templates/autotown_v4/assets/js/basket.js?17898172305808

js autotown.ru collected 2026-10-07 18:08:47 UTC 5,808 bytes, 156 lines download raw bytes

1var fmq_product_map = window.fmq_product_map || (window.fmq_product_map = []);
2
3let FmqBasket = function () {
4
5    let componentName = 'freematiq:sale.basket';
6
7    // основной метод отправки ajax-запросов
8    this._fetch = function (action, data, signedParameters) {
9        return BX.ajax.runComponentAction(
10            componentName,
11            action,
12            {
13                data: data,
14                signedParameters: signedParameters
15            },
16        )
17            .then((response) => this.__fetchSuccess(response, action))
18            .catch((response) => this.__fetchError(response));
19    }
20
21    // общий обработчик успешной отправки
22    this.__fetchSuccess = function (response, action) {
23        if (action === 'addProduct' || action === 'updateQuantity' || action === 'deleteItem' || action === 'deleteMultipleItems') {
24            BX.onCustomEvent('OnBasketChange');
25        }
26        return response;
27    }
28
29    // общий обработик ошибок при отправке
30    this.__fetchError = function (response) {
31        if (response.hasOwnProperty('errors')) {
32            console.error(response.errors);
33        } else {
34            console.error(response);
35        }
36        return response;
37    }
38}
39
40FmqBasket.prototype = {
41    addToBasket: function (productId, arStore) {
42        try {
43            pixelReachGoal({
44                value: fmq_product_map[productId].PRICE,
45                goal: 'add_to_cart',
46                params: {
47                    product_id: productId
48                }
49            });
50        } catch (e) {
51            console.error(e);
52        }
53
54        return this._fetch('addProduct', {
55            productId: productId,
56            arStore: arStore
57        });
58    },
59    setQuantity: function (productId, storeId, quantity) {
60        return this._fetch('setQuantity', {
61            productId: productId,
62            storeId: storeId,
63            quantity: quantity,
64        });
65    },
66    updateQuantity: function (productId, arQuantity) {
67        return this._fetch('updateQuantity', {
68            productId: productId,
69            arQuantity: arQuantity,
70        });
71    },
72    deleteItem: function (productId) {
73        return this._fetch('deleteItem', {
74            productId: productId,
75        });
76    },
77    deleteMultipleItems: function (productIds) {
78        return this._fetch('deleteMultipleItems', {
79            productIds: productIds,
80        });
81    },
82    getBasketData: function (signedParameters) {
83        return this._fetch('getBasketData', {}, signedParameters);
84    }
85}
86
87$(function () {
88    let obBasket = new FmqBasket();
89
90    const basketButton = document.querySelectorAll('.js-addToBasket_modal');
91
92    basketButton.forEach(item => {
93        item.addEventListener('click', function () {
94
95            const currentModal = item.closest('.modal');
96            const currentModalClose = currentModal.querySelector('*[data-close]');
97            const allStoreInputs = currentModal.querySelectorAll('.js_quantity_store');
98
99            try {
100                let arStore = {};
101                const productId = item.getAttribute('data-id');
102
103                allStoreInputs.forEach(input => {
104                    let storeInputId = input.getAttribute('data-id');
105                    let storeInputValue = input.value;
106                    arStore[storeInputId] = parseInt(storeInputValue);
107                });
108
109                let totalAmount = Object.values(arStore).reduce(
110                    (accumulator, currentValue) => accumulator + currentValue, 0
111                );
112
113                if (totalAmount > 0) {
114                    item.setAttribute('disabled', 'true');
115
116                    obBasket.addToBasket(productId, arStore).then(
117                        function (response) {
118                            const addBasketButton = document.querySelector('.js-add-basket-cart[data-id=product-' + productId.toString() + ']');
119
120                            if (addBasketButton) {
121                                addBasketButton.removeAttribute('data-modal');
122                                addBasketButton.setAttribute('href', '/cart/');
123                                addBasketButton.innerHTML = 'В корзине';
124                            }
125
126                            item.removeAttribute('disabled');
127
128
129                            if (currentModalClose) {
130                                currentModalClose.click();
131
132                            }
133
134                            createModal('Товар добавлен в корзин
134у', 'success-basket', '<div class="modal-success-basket">\n' +
135                                '                <a href="/cart/" class="button wide" type="button">\n' +
136                                '                    Перейти в корзину\n' +
137                                '                </a>\n' +
138                                '                <button class="button secondary wide" type="button" data-close="true">\n' +
139                                '                    Вернуться в каталог\n' +
140                                '                </button>\n' +
141                                '            </div>');
142                        }
143                    );
144                } else {
145                    const error = item.parentElement.querySelector('.form__error')
146                    if (error) {
147                        error.style.display = 'block';
148                    }
149                }
150            } catch (err) {
151                console.error(err);
152            }
153        });
154    });
155});
156

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.