{"action":"created","comment":{"url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/comments/33558839","id":33558839,"diff_hunk":"@@ -0,0 +1,95 @@\n+class CartsController < ApplicationController\n+\n+  before_action :create_cart\n+  helper_method :count_cartparams\n+\n+  def additem\n+    #allows only integers larger than zero, else returns an error\n+    if params[:quantity].to_i>0\n+      #if the product isn't already in cart, add a new item to the cart\n+      if session[:cart].select{|a| a['id'].to_i==params[:product_id].to_i}.empty?\n+        #binding.pry\n+        session[:cart].push({'id' => params[:product_id], 'quantity' => params[:quantity]})\n+      #if the product is already in cart, increment quantity by the number of ordered items\n+      else\n+        session[:cart].collect! {|a| (a['id'].to_i==params[:product_id].to_i) ? {'id' => a['id'], 'quantity' => a['quantity'].to_i+params[:quantity].to_i} : a }\n+      end\n+      redirect_to root_url, notice: 'Produkt dodany.'\n+    else\n+      redirect_to root_url, error: 'Błąd. Spróbuj ponownie.'\n+    end\n+    cart_count\n+  end\n+\n+  def edititem\n+    #allows only integers larger than zero, else returns an error\n+    if params[:quantity].to_i>0\n+      #if the product isn't already in cart, add it - it shouldn't happen, but handling is simple\n+      if session[:cart].select{|a| a['id']==params[:product_id]}.empty?\n+        session[:cart].push({'id' => params[:product_id], 'quantity' => params[:quantity]})\n+      #if the product is already in cart, set quantity to the submitted one\n+      else\n+        session[:cart].collect! {|a| (a['id']==params[:product_id]) ? {'id' => a['id'], 'quantity' => params[:quantity].to_i} : a }\n+      end\n+      redirect_to cart_path, notice: 'Produkt zmieniony.'","path":"app/controllers/carts_controller.rb","position":34,"original_position":34,"commit_id":"b033326cec0cd0c9a93f7d5625be453f81fc73f3","original_commit_id":"b033326cec0cd0c9a93f7d5625be453f81fc73f3","user":{"login":"hirokiraj","id":1582486,"avatar_url":"https://avatars.githubusercontent.com/u/1582486?v=3","gravatar_id":"","url":"https://api.github.com/users/hirokiraj","html_url":"https://github.com/hirokiraj","followers_url":"https://api.github.com/users/hirokiraj/followers","following_url":"https://api.github.com/users/hirokiraj/following{/other_user}","gists_url":"https://api.github.com/users/hirokiraj/gists{/gist_id}","starred_url":"https://api.github.com/users/hirokiraj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hirokiraj/subscriptions","organizations_url":"https://api.github.com/users/hirokiraj/orgs","repos_url":"https://api.github.com/users/hirokiraj/repos","events_url":"https://api.github.com/users/hirokiraj/events{/privacy}","received_events_url":"https://api.github.com/users/hirokiraj/received_events","type":"User","site_admin":false},"body":"to samo","created_at":"2015-06-30T10:18:22Z","updated_at":"2015-06-30T10:18:22Z","html_url":"https://github.com/Ciabas/PierogApple/pull/5#discussion_r33558839","pull_request_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/comments/33558839"},"html":{"href":"https://github.com/Ciabas/PierogApple/pull/5#discussion_r33558839"},"pull_request":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5","id":38773178,"html_url":"https://github.com/Ciabas/PierogApple/pull/5","diff_url":"https://github.com/Ciabas/PierogApple/pull/5.diff","patch_url":"https://github.com/Ciabas/PierogApple/pull/5.patch","issue_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/5","number":5,"state":"open","locked":false,"title":"Cart","user":{"login":"Pudlovich","id":12862770,"avatar_url":"https://avatars.githubusercontent.com/u/12862770?v=3","gravatar_id":"","url":"https://api.github.com/users/Pudlovich","html_url":"https://github.com/Pudlovich","followers_url":"https://api.github.com/users/Pudlovich/followers","following_url":"https://api.github.com/users/Pudlovich/following{/other_user}","gists_url":"https://api.github.com/users/Pudlovich/gists{/gist_id}","starred_url":"https://api.github.com/users/Pudlovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pudlovich/subscriptions","organizations_url":"https://api.github.com/users/Pudlovich/orgs","repos_url":"https://api.github.com/users/Pudlovich/repos","events_url":"https://api.github.com/users/Pudlovich/events{/privacy}","received_events_url":"https://api.github.com/users/Pudlovich/received_events","type":"User","site_admin":false},"body":"Cart set up and working properly.\r\n- user is able to add products to cart\r\n- user is able to see his cart\r\n- user can edit the ordered amount in his cart\r\n- user can remove items from his cart\r\n- user can see number of items and their value on the navbar","created_at":"2015-06-29T13:28:00Z","updated_at":"2015-06-30T10:18:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f79363886cbeecaf07c23f98df8392b9f91d2357","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5/commits","review_comments_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5/comments","review_comment_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/5/comments","statuses_url":"https://api.github.com/repos/Ciabas/PierogApple/statuses/b033326cec0cd0c9a93f7d5625be453f81fc73f3","head":{"label":"Ciabas:cart","ref":"cart","sha":"b033326cec0cd0c9a93f7d5625be453f81fc73f3","user":{"login":"Ciabas","id":9249181,"avatar_url":"https://avatars.githubusercontent.com/u/9249181?v=3","gravatar_id":"","url":"https://api.github.com/users/Ciabas","html_url":"https://github.com/Ciabas","followers_url":"https://api.github.com/users/Ciabas/followers","following_url":"https://api.github.com/users/Ciabas/following{/other_user}","gists_url":"https://api.github.com/users/Ciabas/gists{/gist_id}","starred_url":"https://api.github.com/users/Ciabas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ciabas/subscriptions","organizations_url":"https://api.github.com/users/Ciabas/orgs","repos_url":"https://api.github.com/users/Ciabas/repos","events_url":"https://api.github.com/users/Ciabas/events{/privacy}","received_events_url":"https://api.github.com/users/Ciabas/received_events","type":"User","site_admin":false},"repo":{"id":37854726,"name":"PierogApple","full_name":"Ciabas/PierogApple","owner":{"login":"Ciabas","id":9249181,"avatar_url":"https://avatars.githubusercontent.com/u/9249181?v=3","gravatar_id":"","url":"https://api.github.com/users/Ciabas","html_url":"https://github.com/Ciabas","followers_url":"https://api.github.com/users/Ciabas/followers","following_url":"https://api.github.com/users/Ciabas/following{/other_user}","gists_url":"https://api.github.com/users/Ciabas/gists{/gist_id}","starred_url":"https://api.github.com/users/Ciabas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ciabas/subscriptions","organizations_url":"https://api.github.com/users/Ciabas/orgs","repos_url":"https://api.github.com/users/Ciabas/repos","events_url":"https://api.github.com/users/Ciabas/events{/privacy}","received_events_url":"https://api.github.com/users/Ciabas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Ciabas/PierogApple","description":"","fork":false,"url":"https://api.github.com/repos/Ciabas/PierogApple","forks_url":"https://api.github.com/repos/Ciabas/PierogApple/forks","keys_url":"https://api.github.com/repos/Ciabas/PierogApple/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Ciabas/PierogApple/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Ciabas/PierogApple/teams","hooks_url":"https://api.github.com/repos/Ciabas/PierogApple/hooks","issue_events_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/events{/number}","events_url":"https://api.github.com/repos/Ciabas/PierogApple/events","assignees_url":"https://api.github.com/repos/Ciabas/PierogApple/assignees{/user}","branches_url":"https://api.github.com/repos/Ciabas/PierogApple/branches{/branch}","tags_url":"https://api.github.com/repos/Ciabas/PierogApple/tags","blobs_url":"https://api.github.com/repos/Ciabas/PierogApple/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Ciabas/PierogApple/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Ciabas/PierogApple/git/refs{/sha}","trees_url":"https://api.github.com/repos/Ciabas/PierogApple/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Ciabas/PierogApple/statuses/{sha}","languages_url":"https://api.github.com/repos/Ciabas/PierogApple/languages","stargazers_url":"https://api.github.com/repos/Ciabas/PierogApple/stargazers","contributors_url":"https://api.github.com/repos/Ciabas/PierogApple/contributors","subscribers_url":"https://api.github.com/repos/Ciabas/PierogApple/subscribers","subscription_url":"https://api.github.com/repos/Ciabas/PierogApple/subscription","commits_url":"https://api.github.com/repos/Ciabas/PierogApple/commits{/sha}","git_commits_url":"https://api.github.com/repos/Ciabas/PierogApple/git/commits{/sha}","comments_url":"https://api.github.com/repos/Ciabas/PierogApple/comments{/number}","issue_comment_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/comments{/number}","contents_url":"https://api.github.com/repos/Ciabas/PierogApple/contents/{+path}","compare_url":"https://api.github.com/repos/Ciabas/PierogApple/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Ciabas/PierogApple/merges","archive_url":"https://api.github.com/repos/Ciabas/PierogApple/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Ciabas/PierogApple/downloads","issues_url":"https://api.github.com/repos/Ciabas/PierogApple/issues{/number}","pulls_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls{/number}","milestones_url":"https://api.github.com/repos/Ciabas/PierogApple/milestones{/number}","notifications_url":"https://api.github.com/repos/Ciabas/PierogApple/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Ciabas/PierogApple/labels{/name}","releases_url":"https://api.github.com/repos/Ciabas/PierogApple/releases{/id}","created_at":"2015-06-22T12:45:55Z","updated_at":"2015-06-22T12:46:50Z","pushed_at":"2015-06-30T10:14:13Z","git_url":"git://github.com/Ciabas/PierogApple.git","ssh_url":"git@github.com:Ciabas/PierogApple.git","clone_url":"https://github.com/Ciabas/PierogApple.git","svn_url":"https://github.com/Ciabas/PierogApple","homepage":null,"size":452,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"Ciabas:master","ref":"master","sha":"edf459679e1258da07fa508d39ad51e811553726","user":{"login":"Ciabas","id":9249181,"avatar_url":"https://avatars.githubusercontent.com/u/9249181?v=3","gravatar_id":"","url":"https://api.github.com/users/Ciabas","html_url":"https://github.com/Ciabas","followers_url":"https://api.github.com/users/Ciabas/followers","following_url":"https://api.github.com/users/Ciabas/following{/other_user}","gists_url":"https://api.github.com/users/Ciabas/gists{/gist_id}","starred_url":"https://api.github.com/users/Ciabas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ciabas/subscriptions","organizations_url":"https://api.github.com/users/Ciabas/orgs","repos_url":"https://api.github.com/users/Ciabas/repos","events_url":"https://api.github.com/users/Ciabas/events{/privacy}","received_events_url":"https://api.github.com/users/Ciabas/received_events","type":"User","site_admin":false},"repo":{"id":37854726,"name":"PierogApple","full_name":"Ciabas/PierogApple","owner":{"login":"Ciabas","id":9249181,"avatar_url":"https://avatars.githubusercontent.com/u/9249181?v=3","gravatar_id":"","url":"https://api.github.com/users/Ciabas","html_url":"https://github.com/Ciabas","followers_url":"https://api.github.com/users/Ciabas/followers","following_url":"https://api.github.com/users/Ciabas/following{/other_user}","gists_url":"https://api.github.com/users/Ciabas/gists{/gist_id}","starred_url":"https://api.github.com/users/Ciabas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ciabas/subscriptions","organizations_url":"https://api.github.com/users/Ciabas/orgs","repos_url":"https://api.github.com/users/Ciabas/repos","events_url":"https://api.github.com/users/Ciabas/events{/privacy}","received_events_url":"https://api.github.com/users/Ciabas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Ciabas/PierogApple","description":"","fork":false,"url":"https://api.github.com/repos/Ciabas/PierogApple","forks_url":"https://api.github.com/repos/Ciabas/PierogApple/forks","keys_url":"https://api.github.com/repos/Ciabas/PierogApple/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Ciabas/PierogApple/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Ciabas/PierogApple/teams","hooks_url":"https://api.github.com/repos/Ciabas/PierogApple/hooks","issue_events_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/events{/number}","events_url":"https://api.github.com/repos/Ciabas/PierogApple/events","assignees_url":"https://api.github.com/repos/Ciabas/PierogApple/assignees{/user}","branches_url":"https://api.github.com/repos/Ciabas/PierogApple/branches{/branch}","tags_url":"https://api.github.com/repos/Ciabas/PierogApple/tags","blobs_url":"https://api.github.com/repos/Ciabas/PierogApple/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Ciabas/PierogApple/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Ciabas/PierogApple/git/refs{/sha}","trees_url":"https://api.github.com/repos/Ciabas/PierogApple/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Ciabas/PierogApple/statuses/{sha}","languages_url":"https://api.github.com/repos/Ciabas/PierogApple/languages","stargazers_url":"https://api.github.com/repos/Ciabas/PierogApple/stargazers","contributors_url":"https://api.github.com/repos/Ciabas/PierogApple/contributors","subscribers_url":"https://api.github.com/repos/Ciabas/PierogApple/subscribers","subscription_url":"https://api.github.com/repos/Ciabas/PierogApple/subscription","commits_url":"https://api.github.com/repos/Ciabas/PierogApple/commits{/sha}","git_commits_url":"https://api.github.com/repos/Ciabas/PierogApple/git/commits{/sha}","comments_url":"https://api.github.com/repos/Ciabas/PierogApple/comments{/number}","issue_comment_url":"https://api.github.com/repos/Ciabas/PierogApple/issues/comments{/number}","contents_url":"https://api.github.com/repos/Ciabas/PierogApple/contents/{+path}","compare_url":"https://api.github.com/repos/Ciabas/PierogApple/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Ciabas/PierogApple/merges","archive_url":"https://api.github.com/repos/Ciabas/PierogApple/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Ciabas/PierogApple/downloads","issues_url":"https://api.github.com/repos/Ciabas/PierogApple/issues{/number}","pulls_url":"https://api.github.com/repos/Ciabas/PierogApple/pulls{/number}","milestones_url":"https://api.github.com/repos/Ciabas/PierogApple/milestones{/number}","notifications_url":"https://api.github.com/repos/Ciabas/PierogApple/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Ciabas/PierogApple/labels{/name}","releases_url":"https://api.github.com/repos/Ciabas/PierogApple/releases{/id}","created_at":"2015-06-22T12:45:55Z","updated_at":"2015-06-22T12:46:50Z","pushed_at":"2015-06-30T10:14:13Z","git_url":"git://github.com/Ciabas/PierogApple.git","ssh_url":"git@github.com:Ciabas/PierogApple.git","clone_url":"https://github.com/Ciabas/PierogApple.git","svn_url":"https://github.com/Ciabas/PierogApple","homepage":null,"size":452,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5"},"html":{"href":"https://github.com/Ciabas/PierogApple/pull/5"},"issue":{"href":"https://api.github.com/repos/Ciabas/PierogApple/issues/5"},"comments":{"href":"https://api.github.com/repos/Ciabas/PierogApple/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Ciabas/PierogApple/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/Ciabas/PierogApple/statuses/b033326cec0cd0c9a93f7d5625be453f81fc73f3"}}}}