<commit_before>'use strict';

angular.module('shoppingCart')
    .factory('ShoppingCart', [function () {
        var self = this;

        self.cartItems = [];

        function getItems () {
            return self.cartItems;
        }

        function getCount () {
            return self.cartItems.length;
        }

        function getTotal () {
            var total = 0;

            for (var i = 0; i < self.cartItems.length; i++) {
                var cartItem = self.cartItems[i];

                if (cartItem.item.price) {
                    total += cartItem.item.price;
                }
            }

            return total;
        }

        function insertItem (item) {
            if (item) {
                var existingItem = self.cartItems.filter(function (i) { return i.id === item.id})[0];

                if (!existingItem) {
                    var cartItemToInsert = {
                        id: item._id,
                        item: item
                    };

                    self.cartItems.push(cartItemToInsert);
                }
            }
        }

        function removeItem (item) {
            if (item) {
                var itemInCart = self.cartItems.filter(function (i) { return i.id === item._id})[0];
                var indexOfItem = self.cartItems.indexOf(itemInCart);

                self.cartItems.splice(indexOfItem, 1);
            }
        }

        return {
            getItems: getItems,
            getCount: getCount,
            getTotal: getTotal,
            insertItem: insertItem,
            removeItem: removeItem
        };
    }]);<commit_msg>Multiple products insertion intro shopping cart - bug fixed<commit_after>'use strict';

angular.module('shoppingCart')
    .factory('ShoppingCart', [function () {
        var self = this;

        self.cartItems = [];

        function getItems () {
            return self.cartItems;
        }

        function getCount () {
            return self.cartItems.length;
        }

        function getTotal () {
            var total = 0;

            for (var i = 0; i < self.cartItems.length; i++) {
                var cartItem = self.cartItems[i];

                if (cartItem.item.price) {
                    total += cartItem.item.price;
                }
            }

            return total;
        }

        function insertItem (item) {
            if (item) {
                var existingItem = self.cartItems.filter(function (i) { return i.id === item._id})[0];

                if (!existingItem) {
                    var cartItemToInsert = {
                        id: item._id,
                        item: item
                    };

                    self.cartItems.push(cartItemToInsert);
                }
            }
        }

        function removeItem (item) {
            if (item) {
                var itemInCart = self.cartItems.filter(function (i) { return i.id === item._id})[0];
                var indexOfItem = self.cartItems.indexOf(itemInCart);

                self.cartItems.splice(indexOfItem, 1);
            }
        }

        return {
            getItems: getItems,
            getCount: getCount,
            getTotal: getTotal,
            insertItem: insertItem,
            removeItem: removeItem
        };
    }]);
{'fraction_non_alphanumeric': 0.10371938312670094, 'fraction_numerical': 0.0030238887208950713, 'mean_word_length': 1.2023968042609854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4437614', 'n_tokens_mistral': 892, 'n_tokens_neox': 830, 'n_words': 181}