PageSourceSearch

https://www.prpwine.com/wp-content/plugins/idstc-acuta/app/shoppin…ddToCartLinkDirective.js?ver=3.1.20260923.1

js prpwine.com collected 2026-09-25 20:51:46 UTC 11,210 bytes, 191 lines download raw bytes

1(function () {
2    'use strict';
3
4    var app = angular.module('app');
5
6    app.directive('addToCartLinkDirective', function ($q, $http, appService, shoppingCartModel, translationService, $rootScope) {
7        return {
8            restrict: 'E',
9            scope: {
10                sku: '@',
11                cartUrl: '@',
12                selectionsRequired: '@',
13                redirectToViewCartAfterAdd: '@'
14            },
15            replace: true,
16            template: ` <div>
17                            <a  class="addtocartlink hand" 
18                                ng-cloak 
19                                ng-click="addToCartClicked()" 
20                                ng-if="shoppingCartModel.cart.CartID.toLowerCase() == shoppingCartModel.customerCartID || shoppingCartModel.cart.CartID == null">
21                                    {{addToCartText}}
22                            </a>
23                        </div>`,
24            link: function (scope, element, attributes) {             
25                scope.dataReady = false;
26                scope.shoppingCartModel = shoppingCartModel;
27
28                scope.$on("cart.cartIDChanged", function (e, cartID) {
29                    shoppingCartModel.cart.CartID = idstc().getExpirableLocalStorageVar('CartID', idstc_setting_acutacartexpirationseconds);
30                    shoppingCartModel.customerCartID = idstc().getExpirableLocalStorageVar('CustomerCartID', idstc_setting_acutacartexpirationseconds);
31                });
32
33                scope.addToCartClicked = function () {                   
34                    if (scope.selectionsRequired == 'true') { // just redirect to product detail
35                        if (scope.cartUrl == null || scope.cartUrl == '') {
36                            window.location = '/' + shoppingCartModel.translatedPageNames.productDetail + '/' + scope.sku;
37                        }
38                        else {
39                            window.location = '/' + shoppingCartModel.translatedPageNames.productDetail + '/' + scope.cartUrl;
40                        }
41                    }
42                    else { // add to cart
43                        $(document).progressStart();
44
45                        var postVar = {
46                            CartID: shoppingCartModel.cart.CartID,
47                            SKU: scope.sku,
48                            Quantity: 1
49                        };
50
51                        $http.post(apiRoot + 'api/shopping/AddToCart', postVar).then(
52                            function (successResult) {
53                                shoppingCartModel.viewCartInfo = null; // Clear view cart info so it will be refreshed                     
54
55                                var promises = [shoppingCartModel.getViewCartInfoWidget()];
56                                if (idstc_setting_acutaenhancedcarticon == 'on') {
57                                    promises = [shoppingCartModel.getViewCartInfo()];
58                                }
59                                else {
60                                    idstc().processResponse({ response: successResult.data, showNotifications: true });
61                                }
62                                $(document).progressFinish();
63
64                                $q.all(promises).then(function (result) {
65                                    idstc().processResponse({ response: result[0], showNotifications: true });                                    
66                                    shoppingCartModel.sendCartToGoogleTagManager(sh
66oppingCartModel.viewCartInfo);
67                                    scope.addToCartEventToGoogleTagManager(scope.sku);
68                                    scope.klaviyoAddToCart(scope.sku);                                    
69
70                                    if (scope.redirectToViewCartAfterAdd == 'true') {
71                                        window.location = '/' + shoppingCartModel.translatedPageNames.viewCart;
72                                    }
73                                    else {
74                                        $rootScope.$broadcast('cart.showCart', null);
75                                        const customEvent = new CustomEvent('flightShowCart');
76                                        window.dispatchEvent(customEvent);
77                                    }
78                                });
79                            },
80                            function (errorResult) {
81                                idstc().processError({ error: errorResult, showNotifications: true });
82                                $(document).progressFinish();
83                            });
84                    }
85                };
86
87                scope.klaviyoAddToCart = function () {
88                    if (idstc_setting_klaviyopublicapikey != null && idstc_setting_klaviyopublicapikey != '') {
89                        var _learnq = window._learnq || [];
90
91                        let addedProduct = shoppingCartModel.viewCartInfo.OrderLines.find(x => (x.SKU || x.ProductSKU) == scope.sku);
92                        let items = [];
93                        let itemNames = [];
94                        let value = 0;
95
96                        for (let i = 0; i < shoppingCartModel.viewCartInfo.OrderLines.length; i++) {
97                            let product = shoppingCartModel.viewCartInfo.OrderLines[i];
98
99                            value += product.DisplayPrice * product.Quantity;
100
101                            let item = {
102                                "ProductID": product.ProductID,
103                                "SKU": product.SKU || product.ProductSKU,
104                                "ProductName": product.ProductDisplayName,
105                                "Quantity": product.Quantity,
106                                "ItemPrice": product.DisplayPrice,
107                                "RowTotal": product.DisplayPrice * product.Quantity,
108                                "ProductURL": location.protocol + '//' + location.host + '/' + shoppingCartModel.translatedPageNames.productDetail + '/' + (product.CartURL || product.ProductCartUrl || product.SKU || product.ProductSKU),
109                                "ImageURL": product.ProductImage
110                            };
111
112                            items.push(item);
113                            itemNames.push(product.ProductDisplayName);
114                        }
115
116                        _learnq.push(["track", "Added To Cart", {
117                            "$value": value,
118                            "AddedItemProductName": addedProduct.ProductDisplayName,
119                            "AddedItemProductID": addedProduct.ProductID,
120                            "AddedItemSKU": addedProduct.SKU || addedProduct.ProductSKU,
121                            "AddedItemImageURL": addedProduct.ProductImage,
122                            "AddedItemURL": location.protocol + '//' + location.host + '/' + shoppingCartModel.translatedPageNames.productDetail + '/' + (addedProduct.CartURL || addedProduct.ProductCartUrl || addedProduct.SKU || addedProduct.ProductSKU),
123                            "AddedItemPrice": addedProduct.DisplayPrice,
124                            "AddedItemQuantity": 1,
125                            "CheckoutURL": location.protocol + '//' + location.host + '/' + shoppingCartModel.translatedPageNames.subtotal,
126                            "ItemNames": itemNames,
127                            "Items": items
128                        }]);
129                    }
130                }
131
132                scope.addToCartEventToGoogleTagManager = function () {
133                    // if google tag manager is enabled then add 'addToCart' event to datalayer
134                    if (idstc_setting_googletagmanagerid != null && idstc_setting_googletagmanagerid != '') {
135                        let addedProduct = shoppingCartModel.viewCartInfo.OrderLines.find(x => (x.SKU || x.ProductSKU) == scope.sku);
136
137                        if (addedProduct != null) {
138                            dataLayer.push({
139                                'event': 'addToCart',
140                                'ecommerce': {
141                                    'add': {
142                                        'products': [{
143                                            'name': addedProduct.DisplayName,
144                                            'category': '',
145                                            'id': addedProduct.SKU || addedProduct.ProductSKU,
146                                            'price': addedProduct.DisplayPrice,
147                                            'brand': addedProduct.GoogleBrand != null ? addedProduct.GoogleBrand : '',
148                                            'variant': (addedProduct.GoogleColor != null && addedProduct.GoogleColor != '' ? addedProduct.GoogleColor : addedProduct.GoogleSize != null ? addedProduct.GoogleSize : ''),
149                                            'quantity': 1
150                                        }]
151                                    }
152                                }
153                            });
154                        }
155                    }
156                }
157
158                scope.init = function () {
159                    shoppingCartModel.cart.CartID = idstc().getExpirableLocalStorageVar('CartID', idstc_setting_acutacartexpirationseconds);
160
161                    var promises = [appService.makeReady()];
162
163                    $q.all(promises).then(function () {                                                                                               
164                        var promises = [shoppingCartModel.verifyAndSetCart(), translationService.getTranslations('shopping-cart')];
165
166                        $q.all(promises).then(function () {
167                            shoppingCartModel.customerCartID = idstc().getExpirableLocalStorageVar('CustomerCartID', idstc_setting_acutacartexpirationseconds);
168                            if (typeof shoppingCartModel.cart.CartID == 'undefined' || shoppingCartModel.cart.CartID == null) {
169                                shoppingCartModel.cart.CartID = shoppingCartModel.customerCartID;
170                            }
171
172                            if (scope.selectionsRequired == 'true') {
173                                scope.addToCartText = translationService.translations['shopping-cart']['add-to-cart-link-selections-required'] || 'Add To Cart With Selections';                                
174                            }
175                            else if (scope.redirectToViewCartAfterAdd == 'true') {
176                                scope.addToCartText = translationService.translations['shopping-cart']['add-to-cart-link-view-cart'] || 'Add To and Go To Cart';                                
177                            }
178                            else {
179                                scope.addToCartText = translationService.translations['shopping-cart']['add-to-cart-link'] || 'Add To Cart';                                
180                            }
181
182                            scope.dataReady = true;
183                        });
184                    });
185                }
186
187                scope.init();
188            }
189        }
190    });
191})();

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.