PageSourceSearch

https://www.argnord.ru/scripts/_partials/cart/controllers/cartAddController.js

js argnord.ru collected 2026-10-04 12:44:36 UTC 4,164 bytes, 98 lines download raw bytes

1import { PubSub } from "../../../_common/PubSub/PubSub.js";
2
3; (function (ng) {
4    'use strict';
5
6    var cartToolbar,
7        timerPopoverHide;
8
9    var CartAddCtrl = function ($document, $q, $timeout, $window, cartConfig, cartService, moduleService, popoverService, SweetAlert, $translate, domService) {
10
11        var ctrl = this;
12
13        ctrl.$onInit = function () {
14            if (ctrl.source != null && ctrl.source === 'mobile') {
15                cartService.setStateInfo(true);
16            }
17        };
18
19        ctrl.addItem = function (event, offerId, productId, amount, attributesXml, payment, href, mode, lpId, lpUpId, lpEntityId, lpEntityType, lpBlockId, hideShipping, offerIds, modeFrom, lpButtonName) {
20
21            event.preventDefault();
22
23            var isValid = ctrl.cartAddValid(),
24                deferNoop = $q.defer();
25
26            if (isValid === true || isValid == null) {
27
28                if (ctrl.isLoading == true) {
29                    deferNoop.resolve(null);
30                    return deferNoop.promise;
31                }
32
33                ctrl.isLoading = true;
34
35                return cartService.addItem(offerId, productId, amount, attributesXml, payment, mode, lpId, lpEntityId, lpEntityType, lpBlockId, { lpUpId: lpUpId, hideShipping: hideShipping, offerIds: offerIds, modeFrom: modeFrom, lpButtonName: lpButtonName })
36                    .then(function (result) {
37                        if (result[0].status == 'redirect') {
38                            if (result[0].url != null && result[0].url.length > 0) {
39                                $window.location.assign(result[0].url);
40                            }
41                            else {
42                                $window.location.assign(href);
43                            }
44                        } else {
45                            PubSub.publish("add_to_cart", href);
46                            PubSub.publish("cart.add", offerId, productId, amount, attributesXml, result['0'].cartId, event.target);
47                            PubSub.publish("cart.addv2", productId, result['0'].cartId, result['0'].CartItem, event.target);
48                            moduleService.update(['minicartmessage', 'fullcartmessage']).then(ctrl.popoverModule);
49                        }
50                        return result;
51                    })
52                    .then(function (result) {
53                        if (ctrl.source != null && ctrl.source === 'mobile' && result[0].status !== 'redirect') {
54                            cartService.showInfoWithDebounce();
55                        }
56
57                        return result;
58                    })
59                    .finally(function () {
60                        ctrl.isLoading = false;
61                    });
62            } else {
63                deferNoop.resolve(null);
64                return deferNoop.promise;
65            }
66        };
67
68        ctrl.popoverModule = function (content) {
69            if (moduleService.getModule('minicartmessage') != null && content[0].trim().length > 0) {
70
71                $timeout(function () {
72                    popoverService.getPopoverScope('popoverCartToolbar').then(function (popoverScope) {
73
74                        cartToolbar = cartToolbar || document.getElementById('cartToolbar');
75
76                        popoverScope.active(cartToolbar);
77
78                        popoverScope.updatePosition(cartToolbar);
79
80                        if (timerPopoverHide != null) {
81                            $timeout.cancel(timerPopoverHide);
82                        }
83
84                        timerPopoverHide = $timeout(function () {
85                            popoverScope.deactive();
86                        }, 5000);
87                    });
88                }, 0);
89            }
90        };
91    };
92
93    angular.module('cart')
94        .controller('CartAddCtrl', CartAddCtrl);
95
96    CartAddCtrl.$inject = ['$document', '$q', '$timeout', '$window', 'cartConfig', 'cartService', 'moduleService', 'popoverService', 'SweetAlert', '$translate', 'domService'];
97
98})(window.angular);

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.