PageSourceSearch

https://classic.ptotoday.com/components/com_store/app/directives/s…/sfm-product.controller.js?6abe455424a28

js ptotoday.com collected 2026-10-01 11:36:19 UTC 4,341 bytes, 112 lines download raw bytes

1'use strict';
2angular.module('sfmStore')
3    .controller('sfmProductController', function($scope, $state, $order, $products, $analytics) {
4        var vm = this;
5        var order = $order.order;
6        vm.order = $order;
7        vm.analytics = $analytics;
8        vm.packageAllowed = true;
9        vm.insuranceAllowed = false;
10        vm.onePrice = false;
11        vm.hideItem = false;
12        vm.plus = Number(order.school.plus) || 0;
13        
14        /** 
15         * Package products have some special handling:
16         * Users who do not have plus are NOT able to purchase UPGRADES,
17         * Packages WITH plus only have one price,
18         * If a user's school is in the school_insurance table, 
19         * they should be allowed to buy an upgrade no matter what.
20         */
21
22        if($scope.product.type === 'pkg') {
23            $products.getPackageProducts($scope.product.id).then(function(res) {
24                var data = res.data.data;
25                var hasPlus = data.filter(function(item) {
26                    return item.type === 'plus';
27                });
28                if(hasPlus.length == 0) {
29                    //And the package DOES NOT contain a plus membership AND the user DOES NOT have a plus membership
30                    //DO NOT show the item
31                    vm.packageAllowed = false
32                }
33
34                if(hasPlus.length > 0) {
35                    //If the user has plus OR the pkg does NOT contain a plus item
36                    vm.onePrice = true;
37                }
38            })
39        }
40
41        if($scope.product.type === 'rnwl') {
42            $products.getPackageProducts($scope.product.id).then(function(res) {
43                var data = res.data.data;
44                var hasPlus = data.filter(function(item) {
45                    return item.type === 'plus';
46                });
47                if(hasPlus.length == 0) {
48                    //And the package DOES NOT contain a plus membership AND the user DOES NOT have a plus membership
49                    //DO NOT show the item
50                    vm.packageAllowed = false
51                }
52
53                if(hasPlus.length > 0) {
54                    //If the user has plus OR the pkg does NOT contain a plus item
55                    vm.onePrice = true;
56                }
57            })
58        }
59
60        if($scope.product.type === 'show') {
61            order.details.items.forEach(function(item) {
62                vm.hideItem = (item.id === $scope.product.id) ? true : false
63            })
64        }
65
66        /**
67         * $order.order.school.insurance_district is a flag that indicates whether or not the school the
68         * user is associated with is in the school_insurance table
69         * 
70         * if the users school is in the school_insurance table that means they are in a special district
71         * that has some of it's own business rules
72         */
73        $scope.$watch(function() {
74            return parseInt($order.order.school.insurance_district);
75        }, function(newVal) {
76            if(newVal){
77                vm.insuranceAllowed = true    
78            }else{
79                vm.insuranceAllowed = false
80            }
81        });
82
83        $scope.$watch(function() {
84            return $order.order.school.plus;
85        }, function(newVal, oldVal) {
86            vm.plus = Number(newVal);
87        });
88
89        vm.onPlusStatusClick = function() {
90            $sfmPlusUnlock.showModal();
91        }
92
93        vm.addToCart = function(item) {
94            var alreadyInCart = $order.getOrder().details.items.filter(function(elem) { return elem.id === item.id });
95            if(item.allow_qty == 1 || alreadyInCart.length === 0) {
96                $order.addOrderItem(item);
97                dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
98                dataLayer.push({
99                  'event': 'add_to_cart',
100                  'ecommerce': {
101                    'items': [{
102                      'item_name': item.title,
103                      'item_id': String(item.id),
104                      'item_category': String(item.category_id),
105                      'quantity': item.qty
106                    }]
107                  }
108                });
109            }
110            $state.go('cart', {previousPage: vm.category_id, itemAdded: item});
111        }
112    })

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.