{"action":"created","comment":{"url":"https://api.github.com/repos/andela/getmyshop/pulls/comments/51347015","id":51347015,"diff_hunk":"@@ -0,0 +1,163 @@\n+function shoppingCart(cartName) {\n+    this.cartName = cartName;\n+    this.items = [];\n+    this.clearCart = false;\n+\n+    this.loadItems();\n+    var self = this;\n+    $(window).unload(function () {\n+        if (self.clearCart) {\n+            self.clearItems();\n+        }\n+        self.saveItems();\n+        self.clearCart = false;\n+    });\n+}\n+\n+shoppingCart.prototype.loadItems = function () {\n+    var items = localStorage !== null ? localStorage[this.cartName + \"_items\"] : null;\n+    if (items !== null && JSON !== null) {\n+        try {\n+            items = JSON.parse(items);\n+            for (var i = 0; i < items.length; i++) {\n+                var item = items[i];\n+                if (item.code !== null && item.name !== null && item.price\n+                        !== null && item.quantity != null &&\n+                        item.image != null) {\n+                    item = new cartItem(\n+                        item.code,\n+                        item.name,\n+                        item.price,\n+                        item.quantity,\n+                        item.image\n+                    );\n+                    this.items.push(item);\n+                }\n+            }\n+        }\n+        catch (err) {\n+            // ignore errors while loading...\n+        }\n+    }\n+};\n+\n+shoppingCart.prototype.saveItems = function () {\n+    if (localStorage !== null && JSON !== null) {\n+        localStorage[this.cartName + \"_items\"] = JSON.stringify(this.items);\n+    }\n+};\n+\n+// adds an item to the cart\n+shoppingCart.prototype.addItem = function (code, name, price, quantity, image) {\n+    quantity = this.toNumber(quantity);\n+    if (quantity !== 0) {\n+\n+        // update quantity for existing item\n+        var found = false;\n+        for (var i = 0; i < this.items.length && !found; i++) {\n+            var item = this.items[i];\n+            if (item.code == code) {\n+                found = true;\n+                item.quantity = this.toNumber(item.quantity + quantity);\n+                if (item.quantity <= 0) {\n+                    this.items.splice(i, 1);\n+                }\n+            }\n+        }\n+\n+        // new item, add now\n+        if (!found) {\n+            item = new cartItem(code, name, price, quantity, image);\n+            this.items.push(item);","path":"app/assets/javascripts/cart.js","position":71,"original_position":71,"commit_id":"59210680fa8e6a3f619fd5de4cbdd00f10225ad9","original_commit_id":"59210680fa8e6a3f619fd5de4cbdd00f10225ad9","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"'item' used out of scope.","created_at":"2016-01-30T16:20:56Z","updated_at":"2016-01-30T16:20:56Z","html_url":"https://github.com/andela/getmyshop/pull/40#discussion_r51347015","pull_request_url":"https://api.github.com/repos/andela/getmyshop/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/comments/51347015"},"html":{"href":"https://github.com/andela/getmyshop/pull/40#discussion_r51347015"},"pull_request":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/andela/getmyshop/pulls/40","id":57488991,"html_url":"https://github.com/andela/getmyshop/pull/40","diff_url":"https://github.com/andela/getmyshop/pull/40.diff","patch_url":"https://github.com/andela/getmyshop/pull/40.patch","issue_url":"https://api.github.com/repos/andela/getmyshop/issues/40","number":40,"state":"open","locked":false,"title":"Items can now be added to cart","user":{"login":"andela-ydaniju","id":15727660,"avatar_url":"https://avatars.githubusercontent.com/u/15727660?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-ydaniju","html_url":"https://github.com/andela-ydaniju","followers_url":"https://api.github.com/users/andela-ydaniju/followers","following_url":"https://api.github.com/users/andela-ydaniju/following{/other_user}","gists_url":"https://api.github.com/users/andela-ydaniju/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-ydaniju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-ydaniju/subscriptions","organizations_url":"https://api.github.com/users/andela-ydaniju/orgs","repos_url":"https://api.github.com/users/andela-ydaniju/repos","events_url":"https://api.github.com/users/andela-ydaniju/events{/privacy}","received_events_url":"https://api.github.com/users/andela-ydaniju/received_events","type":"User","site_admin":false},"body":"Why?\r\nUsers should be able to add products to cart\r\n\r\nHow?\r\n- Get product attributes from form on clicking 'add to cart'\r\n- Save attributes into local storage\r\n- Update DOM elements with information in local storage\r\n\r\nhttps://www.pivotaltracker.com/story/show/110060166\r\n[Finishes #110060166]","created_at":"2016-01-28T11:26:52Z","updated_at":"2016-01-30T16:20:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b689e9894279092dc1c30cb655c94e75a53d8b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/andela/getmyshop/pulls/40/commits","review_comments_url":"https://api.github.com/repos/andela/getmyshop/pulls/40/comments","review_comment_url":"https://api.github.com/repos/andela/getmyshop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela/getmyshop/issues/40/comments","statuses_url":"https://api.github.com/repos/andela/getmyshop/statuses/59210680fa8e6a3f619fd5de4cbdd00f10225ad9","head":{"label":"andela:ft-add-to-cart-110060166","ref":"ft-add-to-cart-110060166","sha":"59210680fa8e6a3f619fd5de4cbdd00f10225ad9","user":{"login":"andela","id":4100206,"avatar_url":"https://avatars.githubusercontent.com/u/4100206?v=3","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":45830862,"name":"getmyshop","full_name":"andela/getmyshop","owner":{"login":"andela","id":4100206,"avatar_url":"https://avatars.githubusercontent.com/u/4100206?v=3","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/getmyshop","description":"Online shop for rent","fork":false,"url":"https://api.github.com/repos/andela/getmyshop","forks_url":"https://api.github.com/repos/andela/getmyshop/forks","keys_url":"https://api.github.com/repos/andela/getmyshop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/getmyshop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/getmyshop/teams","hooks_url":"https://api.github.com/repos/andela/getmyshop/hooks","issue_events_url":"https://api.github.com/repos/andela/getmyshop/issues/events{/number}","events_url":"https://api.github.com/repos/andela/getmyshop/events","assignees_url":"https://api.github.com/repos/andela/getmyshop/assignees{/user}","branches_url":"https://api.github.com/repos/andela/getmyshop/branches{/branch}","tags_url":"https://api.github.com/repos/andela/getmyshop/tags","blobs_url":"https://api.github.com/repos/andela/getmyshop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/getmyshop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/getmyshop/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/getmyshop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/getmyshop/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/getmyshop/languages","stargazers_url":"https://api.github.com/repos/andela/getmyshop/stargazers","contributors_url":"https://api.github.com/repos/andela/getmyshop/contributors","subscribers_url":"https://api.github.com/repos/andela/getmyshop/subscribers","subscription_url":"https://api.github.com/repos/andela/getmyshop/subscription","commits_url":"https://api.github.com/repos/andela/getmyshop/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/getmyshop/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/getmyshop/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/getmyshop/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/getmyshop/contents/{+path}","compare_url":"https://api.github.com/repos/andela/getmyshop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/getmyshop/merges","archive_url":"https://api.github.com/repos/andela/getmyshop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/getmyshop/downloads","issues_url":"https://api.github.com/repos/andela/getmyshop/issues{/number}","pulls_url":"https://api.github.com/repos/andela/getmyshop/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/getmyshop/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/getmyshop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/getmyshop/labels{/name}","releases_url":"https://api.github.com/repos/andela/getmyshop/releases{/id}","deployments_url":"https://api.github.com/repos/andela/getmyshop/deployments","created_at":"2015-11-09T10:22:52Z","updated_at":"2016-01-12T16:45:51Z","pushed_at":"2016-01-30T16:20:29Z","git_url":"git://github.com/andela/getmyshop.git","ssh_url":"git@github.com:andela/getmyshop.git","clone_url":"https://github.com/andela/getmyshop.git","svn_url":"https://github.com/andela/getmyshop","homepage":null,"size":1106,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"andela:master","ref":"master","sha":"1d6489dedb693a1c07ec11f6036c254ad88b8304","user":{"login":"andela","id":4100206,"avatar_url":"https://avatars.githubusercontent.com/u/4100206?v=3","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":45830862,"name":"getmyshop","full_name":"andela/getmyshop","owner":{"login":"andela","id":4100206,"avatar_url":"https://avatars.githubusercontent.com/u/4100206?v=3","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/getmyshop","description":"Online shop for rent","fork":false,"url":"https://api.github.com/repos/andela/getmyshop","forks_url":"https://api.github.com/repos/andela/getmyshop/forks","keys_url":"https://api.github.com/repos/andela/getmyshop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/getmyshop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/getmyshop/teams","hooks_url":"https://api.github.com/repos/andela/getmyshop/hooks","issue_events_url":"https://api.github.com/repos/andela/getmyshop/issues/events{/number}","events_url":"https://api.github.com/repos/andela/getmyshop/events","assignees_url":"https://api.github.com/repos/andela/getmyshop/assignees{/user}","branches_url":"https://api.github.com/repos/andela/getmyshop/branches{/branch}","tags_url":"https://api.github.com/repos/andela/getmyshop/tags","blobs_url":"https://api.github.com/repos/andela/getmyshop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/getmyshop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/getmyshop/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/getmyshop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/getmyshop/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/getmyshop/languages","stargazers_url":"https://api.github.com/repos/andela/getmyshop/stargazers","contributors_url":"https://api.github.com/repos/andela/getmyshop/contributors","subscribers_url":"https://api.github.com/repos/andela/getmyshop/subscribers","subscription_url":"https://api.github.com/repos/andela/getmyshop/subscription","commits_url":"https://api.github.com/repos/andela/getmyshop/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/getmyshop/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/getmyshop/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/getmyshop/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/getmyshop/contents/{+path}","compare_url":"https://api.github.com/repos/andela/getmyshop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/getmyshop/merges","archive_url":"https://api.github.com/repos/andela/getmyshop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/getmyshop/downloads","issues_url":"https://api.github.com/repos/andela/getmyshop/issues{/number}","pulls_url":"https://api.github.com/repos/andela/getmyshop/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/getmyshop/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/getmyshop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/getmyshop/labels{/name}","releases_url":"https://api.github.com/repos/andela/getmyshop/releases{/id}","deployments_url":"https://api.github.com/repos/andela/getmyshop/deployments","created_at":"2015-11-09T10:22:52Z","updated_at":"2016-01-12T16:45:51Z","pushed_at":"2016-01-30T16:20:29Z","git_url":"git://github.com/andela/getmyshop.git","ssh_url":"git@github.com:andela/getmyshop.git","clone_url":"https://github.com/andela/getmyshop.git","svn_url":"https://github.com/andela/getmyshop","homepage":null,"size":1106,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/40"},"html":{"href":"https://github.com/andela/getmyshop/pull/40"},"issue":{"href":"https://api.github.com/repos/andela/getmyshop/issues/40"},"comments":{"href":"https://api.github.com/repos/andela/getmyshop/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela/getmyshop/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/andela/getmyshop/statuses/59210680fa8e6a3f619fd5de4cbdd00f10225ad9"}}}}