simple_cart 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/simple_cart/address.rb +12 -0
  3. data/app/models/simple_cart/asda.rb +4 -0
  4. data/app/models/simple_cart/billing_address.rb +4 -0
  5. data/app/models/simple_cart/cart.rb +74 -0
  6. data/app/models/simple_cart/credit_card.rb +24 -0
  7. data/app/models/simple_cart/delivery.rb +6 -0
  8. data/app/models/simple_cart/order.rb +60 -0
  9. data/app/models/simple_cart/order_item.rb +6 -0
  10. data/app/models/simple_cart/shipping_address.rb +4 -0
  11. data/app/views/simple_cart/checkout/_address.html.haml +1 -1
  12. data/app/views/simple_cart/checkout/_summary.html.haml +4 -4
  13. data/app/views/simple_cart/checkout/billing.html.haml +1 -1
  14. data/app/views/simple_cart/checkout/delivery.html.haml +2 -2
  15. data/app/views/simple_cart/checkout/payment.html.haml +2 -2
  16. data/db/migrate/{20160312121928_create_order_item.rb → 20160312121928_create_simple_cart_order_item.rb} +5 -5
  17. data/db/migrate/{20160312124050_create_order.rb → 20160312124050_create_simple_cart_order.rb} +3 -3
  18. data/db/migrate/{20160312142534_address.rb → 20160312142534_create_simple_cart_address.rb} +4 -4
  19. data/db/migrate/{20160312145452_delivery.rb → 20160312145452_create_simple_cart_delivery.rb} +3 -2
  20. data/db/migrate/{20160312151237_add_credit_card.rb → 20160312151237_create_simple_cart_credit_card.rb} +3 -3
  21. data/db/migrate/20160314183842_create_simple_cart_asdas.rb +10 -0
  22. data/lib/simple_cart/version.rb +1 -1
  23. data/lib/tasks/simple_cart_tasks.rake +19 -4
  24. data/test/dummy/app/assets/javascripts/things.js +2 -0
  25. data/test/dummy/app/assets/stylesheets/things.scss +3 -0
  26. data/test/dummy/app/controllers/application_controller.rb +0 -2
  27. data/test/dummy/app/controllers/things_controller.rb +58 -0
  28. data/test/dummy/app/helpers/things_helper.rb +2 -0
  29. data/test/dummy/app/models/thing.rb +2 -0
  30. data/test/dummy/app/views/{items → things}/_form.html.erb +4 -4
  31. data/test/dummy/app/views/things/edit.html.erb +6 -0
  32. data/test/dummy/app/views/things/index.html.erb +31 -0
  33. data/test/dummy/app/views/things/new.html.erb +5 -0
  34. data/test/dummy/app/views/things/show.html.erb +21 -0
  35. data/test/dummy/config/routes.rb +1 -0
  36. data/test/dummy/db/development.sqlite3 +0 -0
  37. data/test/dummy/db/migrate/{20160312124601_create_order_items.simple_cart.rb → 20160314184432_create_simple_cart_order_item.simple_cart.rb} +5 -5
  38. data/test/dummy/db/migrate/{20160312124602_create_order.simple_cart.rb → 20160314184433_create_simple_cart_order.simple_cart.rb} +4 -4
  39. data/test/dummy/db/migrate/{20160312142752_address.simple_cart.rb → 20160314184434_create_simple_cart_address.simple_cart.rb} +4 -4
  40. data/test/dummy/db/migrate/{20160312145636_delivery.simple_cart.rb → 20160314184435_create_simple_cart_delivery.simple_cart.rb} +3 -2
  41. data/test/dummy/db/migrate/{20160312151409_add_credit_card.simple_cart.rb → 20160314184436_create_simple_cart_credit_card.simple_cart.rb} +3 -3
  42. data/test/dummy/db/migrate/20160314184437_create_simple_cart_asdas.simple_cart.rb +11 -0
  43. data/test/dummy/db/migrate/{20160307150139_create_items.rb → 20160314184745_create_things.rb} +2 -2
  44. data/test/dummy/db/schema.rb +21 -29
  45. data/test/dummy/log/development.log +3814 -0
  46. data/test/dummy/test/controllers/things_controller_test.rb +49 -0
  47. data/test/dummy/test/models/{item_test.rb → thing_test.rb} +1 -1
  48. data/test/dummy/tmp/cache/assets/sprockets/v3.0/-sMBlUbMCruloZiGwXAkZ5qkMXnSOfizEHh42yfICOo.cache +1 -0
  49. data/test/dummy/tmp/cache/assets/sprockets/v3.0/2do6_0BJY_m-WISNQO55OL7r8EryK6F5GT875Vmdr_I.cache +0 -0
  50. data/test/dummy/tmp/cache/assets/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +0 -0
  51. data/test/dummy/tmp/cache/assets/sprockets/v3.0/6rr48iVYpUE7q2m5J4DGmbU2hoaoT94T1TKw0hx2MgU.cache +0 -0
  52. data/test/dummy/tmp/cache/assets/sprockets/v3.0/83NGEE7Dkkuzj_aphqH3WxVn5hHfKVawDdEztQSpGF8.cache +1 -0
  53. data/test/dummy/tmp/cache/assets/sprockets/v3.0/8DXxFxOs3XK06Mxa2Ob19isXxUDJ28PqKZkHvaWv75Y.cache +0 -0
  54. data/test/dummy/tmp/cache/assets/sprockets/v3.0/AYBEyhZJ0H2jvcUYmWfnUsg-5ecns9BP_8fxyreMlek.cache +1 -0
  55. data/test/dummy/tmp/cache/assets/sprockets/v3.0/BgsENjJNIUiGA7nr7BkOYU8zcNW6XeB6BNNv4MWjWaQ.cache +0 -0
  56. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Cl6gPwmWN2Yt_JZfRenwju2AwmuvMazp847XaP4iwOU.cache +0 -0
  57. data/test/dummy/tmp/cache/assets/sprockets/v3.0/DSOLSc6A5RVSmvM415eEWAWG_AgOvZcLZOXQjsXyWQA.cache +0 -0
  58. data/test/dummy/tmp/cache/assets/sprockets/v3.0/EsPwaYrEK5VY70wbjmozW82BnI3AeMHHznHT1y4or0s.cache +0 -0
  59. data/test/dummy/tmp/cache/assets/sprockets/v3.0/I7zER_NAw46Rh3MUqyIlZQcYUzI_b9jGGDuf8unwfAA.cache +0 -0
  60. data/test/dummy/tmp/cache/assets/sprockets/v3.0/LuVuixjEF7YqVs6naYiDzEQs17oZrgPjH7xBIna-dFk.cache +0 -0
  61. data/test/dummy/tmp/cache/assets/sprockets/v3.0/N3ynYTk1iq-DkvgrkhdDk2fFBaCqcroKAfKK0fOuq4M.cache +1 -0
  62. data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +0 -0
  63. data/test/dummy/tmp/cache/assets/sprockets/v3.0/QmeozvaJCXEZgrsu54HdlAztW40N4GgOr5Euwv1_b6I.cache +0 -0
  64. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Rj42BFwHvQpHPnt1iAOPi89OYrjqGtGG_4wceo2BBJU.cache +3 -0
  65. data/test/dummy/tmp/cache/assets/sprockets/v3.0/XnsVm-Zv77KyLk_T1Ir1BbtWmQONMpeQ8oFiw0youEs.cache +0 -0
  66. data/test/dummy/tmp/cache/assets/sprockets/v3.0/XpaMhBmfnKXevKG9G3pnDyi2I__eqrtiSScrPOQISJQ.cache +0 -0
  67. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Z0hYz4kAc0qIHZh2B6PKbQzGp-o9iOHeG4p6UZ5I79g.cache +1 -0
  68. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Z2uWpFgWmN5mCkSLFelYcIHrd3Hg_jZvl3OToBURIx0.cache +1 -0
  69. data/test/dummy/tmp/cache/assets/sprockets/v3.0/ZE1rEtR4O5c-wrMABt6kf3KPw9ANKgCvDLl_HKA67tw.cache +0 -0
  70. data/test/dummy/tmp/cache/assets/sprockets/v3.0/_lZdgp3oIruAKbhu6WtQOSgdulGjDuxwvsZYlqQhvgs.cache +1 -0
  71. data/test/dummy/tmp/cache/assets/sprockets/v3.0/a-QY9no1r9wESk0XVZMU9-j4ILaT0dYl4wZXDp81u-Y.cache +0 -0
  72. data/test/dummy/tmp/cache/assets/sprockets/v3.0/bGACHbYazmadJKSmeRj-qOtfk2VhzZVNcCtZeJjWdnQ.cache +1 -0
  73. data/test/dummy/tmp/cache/assets/sprockets/v3.0/gZp3uXMHuYQC4hzCr7bQfetKNdJAtbQmg3so2KpW1Dw.cache +0 -0
  74. data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +0 -0
  75. data/test/dummy/tmp/cache/assets/sprockets/v3.0/ibD5UKGyxBi5Ku5BUV1vG7rslb0drFn8WSbtt5IIUjI.cache +0 -0
  76. data/test/dummy/tmp/cache/assets/sprockets/v3.0/kQrLKly_-oWaLlXxLU1kJ_f2RGKSegikbCSLB6ngQb0.cache +1 -0
  77. data/test/dummy/tmp/cache/assets/sprockets/v3.0/lK1OKrUN4Aa4ULF5iC8LIO9b_8pD6VtM7QmFoR_Hyq4.cache +3 -0
  78. data/test/dummy/tmp/cache/assets/sprockets/v3.0/nwZ7OlaT5CopAytu4Wj7C2dIhJATxQcr9-llmxhvr24.cache +0 -0
  79. data/test/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +0 -0
  80. data/test/dummy/tmp/cache/assets/sprockets/v3.0/qEqxPoB4kreE79i9bMtvzfKkwN0k6R3RiGyGNqfu3hg.cache +1 -0
  81. data/test/dummy/tmp/cache/assets/sprockets/v3.0/qWFB2-t9pKzO4Y2L9nrDJ--Il_NK1G6W1VTOZmp7NEU.cache +1 -0
  82. data/test/dummy/tmp/cache/assets/sprockets/v3.0/rX4eaTmGdGCEW9N1MaxQaGYQf6Ai9y7fx-tYKEkWKSg.cache +0 -0
  83. data/test/dummy/tmp/cache/assets/sprockets/v3.0/tC2-EIZv61P8CEFijr9uxHBmHtSivZyE-y3KOR5Th7k.cache +2 -0
  84. data/test/dummy/tmp/cache/assets/sprockets/v3.0/upXyvpsevxXjLhjtNkXE1yKW2WpRPLP3icept_dAfDc.cache +1 -0
  85. data/test/dummy/tmp/cache/assets/sprockets/v3.0/vo2uJ1UBvSksPJ8Tv0I29pH8zcKe_PwMZa2RIXHCyfU.cache +1 -0
  86. data/test/dummy/tmp/pids/server.pid +1 -1
  87. data/test/{dummy/test/fixtures/items.yml → fixtures/simple_cart/asdas.yml} +4 -6
  88. data/test/fixtures/simple_cart/sssses.yml +11 -0
  89. data/test/fixtures/simple_cart/tests.yml +11 -0
  90. data/test/models/simple_cart/asda_test.rb +9 -0
  91. data/test/models/simple_cart/ssss_test.rb +9 -0
  92. data/test/models/simple_cart/test_test.rb +9 -0
  93. metadata +164 -101
  94. data/README.rdoc +0 -3
  95. data/app/models/address.rb +0 -10
  96. data/app/models/billing_address.rb +0 -2
  97. data/app/models/cart.rb +0 -71
  98. data/app/models/credit_card.rb +0 -22
  99. data/app/models/delivery.rb +0 -4
  100. data/app/models/order.rb +0 -58
  101. data/app/models/order_item.rb +0 -4
  102. data/app/models/shipping_address.rb +0 -2
  103. data/test/dummy/app/models/bicycle.rb +0 -2
  104. data/test/dummy/app/models/coupon.rb +0 -2
  105. data/test/dummy/app/models/item.rb +0 -2
  106. data/test/dummy/app/views/bicycles/_form.html.erb +0 -29
  107. data/test/dummy/app/views/bicycles/edit.html.erb +0 -6
  108. data/test/dummy/app/views/bicycles/index.html.erb +0 -31
  109. data/test/dummy/app/views/bicycles/new.html.erb +0 -5
  110. data/test/dummy/app/views/bicycles/show.html.erb +0 -21
  111. data/test/dummy/app/views/items/edit.html.erb +0 -6
  112. data/test/dummy/app/views/items/index.html.erb +0 -31
  113. data/test/dummy/app/views/items/new.html.erb +0 -5
  114. data/test/dummy/app/views/items/show.html.erb +0 -25
  115. data/test/dummy/db/migrate/20160310215421_create_bicycles.rb +0 -11
  116. data/test/dummy/db/migrate/20160310231528_create_coupons.rb +0 -10
  117. data/test/dummy/db/migrate/20160312142751_create_order_item.simple_cart.rb +0 -17
  118. data/test/dummy/db/migrate/20160312151033_fix.simple_cart.rb +0 -6
  119. data/test/dummy/test/models/bicycle_test.rb +0 -7
  120. /data/test/dummy/app/views/layouts/{application2.html.erb → application.html.erb} +0 -0
  121. /data/test/dummy/test/fixtures/{bicycles.yml → things.yml} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58ec7d937d4194c6e2d19fcaceffe7e12a9e6ac6
4
- data.tar.gz: 7d56e634d8d307cfe8a01f778df48f13b8c74173
3
+ metadata.gz: 6148409ab1f3ae853be9e98ba3f16af6d0240b0e
4
+ data.tar.gz: fced1198da49b7cf588d8526a6ab3b8e3aa5769f
5
5
  SHA512:
6
- metadata.gz: ca2226a2855d96b03fcdcd803e73e13bb939a7fe7a9543210960307d5982c85d8fd61996c0ebf668334850b9e40c484a30057d5cf0c53dea81262ac059753838
7
- data.tar.gz: 13c1f5ce9661cfa0bb203fd986092d8634238eaff679456e7f6cdb603c5a27ffc82a8750e34c1d89fb275bde07a9108534b190a5fc384a30dc3e70ea10a95d5f
6
+ metadata.gz: 2d3de51ea38123ab5e89c6fc1b597f9941f29d5f68c2c5e41e16912bd67c3bfed09429fd1bbfe874785714aa1f689a71d26f23b5c04088281e9bf952489d1119
7
+ data.tar.gz: 31926b4b46d773af9e11350f2e51de4d0571c6aee918b6b1801d73aa2a532aa66901ff1b5d3d55d420de94dd3797a906dbdc8642ce19973cb0201cc8ad92dad2
@@ -0,0 +1,12 @@
1
+ module SimpleCart
2
+ class Address < ActiveRecord::Base
3
+ belongs_to :user
4
+ belongs_to :order
5
+
6
+ validates :firstname, :lastname, :address, :zipcode, :city, :phone, :country, presence: true
7
+
8
+ def self.countries
9
+ ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleCart
2
+ class Asda < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleCart
2
+ class BillingAddress < Address
3
+ end
4
+ end
@@ -0,0 +1,74 @@
1
+ module SimpleCart
2
+
3
+ class Cart
4
+
5
+ attr_accessor :session
6
+
7
+ def initialize(cart_session)
8
+ @session = cart_session
9
+ end
10
+
11
+ def subtotal
12
+ subtotal = 0
13
+ unless @session.nil?
14
+ @session.each do |k, v|
15
+ subtotal += k.split('_')[0].constantize.find(k.split('_')[1]).price * v
16
+ end
17
+ subtotal -= @discount unless @discount.nil?
18
+ subtotal
19
+ end
20
+ end
21
+
22
+ def items
23
+ unless @session.nil?
24
+ arr = []
25
+ @session.each do |k, v|
26
+ arr << k.split('_')[0].constantize.find(k.split('_')[1])
27
+ end
28
+ arr
29
+ end
30
+ end
31
+
32
+ def order_items
33
+ items = []
34
+ self.items.each do |item|
35
+ items << OrderItem.new(price: item.price, qty: @session["#{item.class}_#{item.id}".to_s], itemable: item)
36
+ end
37
+ items
38
+ end
39
+
40
+ def build_order
41
+ order = Order.new(total_price: self.subtotal, completed_date: Time.now)
42
+ order.order_items << self.order_items
43
+ order
44
+ end
45
+
46
+ def add_item(book_id, qty)
47
+ qty = 1 unless qty > 0
48
+ @session[book_id].nil? ? @session[book_id] = qty : @session[book_id] += qty
49
+ end
50
+
51
+ def remove_item(item_id)
52
+ @session.delete(item_id)
53
+ end
54
+
55
+ def update_books(params)
56
+ @session.each do |k, v|
57
+ params[k] = 1 unless params[k].to_i > 0
58
+ @session[k] = params[k].to_i
59
+ end
60
+ @discount = discount(params[:coupon]) if using_coupon?
61
+ end
62
+
63
+ def using_coupon?
64
+ SimpleCart.coupon_class
65
+ rescue
66
+ false
67
+ end
68
+
69
+ def discount(code=nil)
70
+ coupon = SimpleCart.coupon_class.find_by(code: code)
71
+ self.subtotal * (coupon.discount / 100.0) unless coupon.nil?
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,24 @@
1
+ module SimpleCart
2
+ class CreditCard < ActiveRecord::Base
3
+ belongs_to :user
4
+ belongs_to :order
5
+
6
+ validates :number, :cvv, :expiration_year, :expiration_month, :firstname, :lastname, presence: true
7
+ validates :number, :cvv, :expiration_year, :expiration_month, numericality: true
8
+ validates :number, :length => { :is => 16 }
9
+ validates :cvv, :length => { :is => 3 }
10
+
11
+
12
+ def name
13
+ number
14
+ end
15
+
16
+ def self.months
17
+ ('01'..'12').to_a
18
+ end
19
+
20
+ def self.years
21
+ (Time.now.year+1..Time.now.year+50).to_a
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ module SimpleCart
2
+ class Delivery < ActiveRecord::Base
3
+ has_many :orders
4
+ validates :company, presence: true
5
+ end
6
+ end
@@ -0,0 +1,60 @@
1
+ module SimpleCart
2
+ class Order < ActiveRecord::Base
3
+ include AASM
4
+ belongs_to :delivery
5
+
6
+ has_many :order_items, dependent: :destroy
7
+ has_one :credit_card, dependent: :destroy
8
+ has_one :billing_address, dependent: :destroy
9
+ has_one :shipping_address, dependent: :destroy
10
+
11
+ accepts_nested_attributes_for :shipping_address
12
+ accepts_nested_attributes_for :billing_address
13
+ accepts_nested_attributes_for :credit_card
14
+
15
+
16
+ validates :total_price, :completed_date, :aasm_state, presence: true
17
+ validates :total_price, numericality: true
18
+
19
+ aasm do
20
+ state :in_progress, :initial => true
21
+ state :in_queue
22
+ state :in_delivery
23
+ state :delivered
24
+ state :canceled
25
+
26
+ event :queued do
27
+ transitions :from => :in_progress, :to => :in_queue
28
+ end
29
+ end
30
+
31
+ ['billing_address', 'shipping_address', 'credit_card'].each do |method|
32
+ define_method("build_or_find_#{method}") do
33
+ self.instance_eval(method).nil? ? instance_eval("build_#{method}") : instance_eval(method)
34
+ # return instance_eval(method) unless self.instance_eval(method).nil?
35
+ # return instance_eval("build_#{method}(user.instance_eval(method).attributes.except('id', 'user_id'))") unless user.instance_eval(method).nil?
36
+ # return instance_eval("build_#{method}") if self.instance_eval(method).nil? && user.instance_eval(method).nil?
37
+ end
38
+ end
39
+
40
+ # rails_admin do
41
+ # edit do
42
+ # include_all_fields
43
+ # end
44
+ # list do
45
+ # field :id
46
+ # field :aasm_state
47
+ # field :total_price
48
+ # include_all_fields
49
+ # end
50
+ # end
51
+
52
+ def subtotal
53
+ order_items.inject(0) { |n, order_item| n += order_item.price * order_item.qty }
54
+ end
55
+
56
+ # def aasm_state_enum
57
+ # self.class.aasm.states_for_select
58
+ # end
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ module SimpleCart
2
+ class OrderItem < ActiveRecord::Base
3
+ belongs_to :itemable, polymorphic: true
4
+ belongs_to :order
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleCart
2
+ class ShippingAddress < Address
3
+ end
4
+ end
@@ -18,4 +18,4 @@
18
18
  = ff.text_field :phone, class: 'form-control'
19
19
  .form-group
20
20
  = ff.label :country
21
- = ff.collection_select :country, Address.countries, :to_s, :to_s, {}, {class: 'form-control'}
21
+ = ff.collection_select :country, SimpleCart::Address.countries, :to_s, :to_s, {}, {class: 'form-control'}
@@ -1,14 +1,14 @@
1
1
  %p
2
2
  Item Total:
3
3
  %strong
4
- = number_to_currency(Order.find(params[:order_id]).total_price)
4
+ = number_to_currency(SimpleCart::Order.find(params[:order_id]).total_price)
5
5
 
6
- - unless Order.find(params[:order_id]).delivery.nil?
6
+ - unless SimpleCart::Order.find(params[:order_id]).delivery.nil?
7
7
  %p
8
8
  Shipping:
9
9
  %strong
10
- = number_to_currency(Order.find(params[:order_id]).delivery.costs)
10
+ = number_to_currency(SimpleCart::Order.find(params[:order_id]).delivery.costs)
11
11
  %p
12
12
  Order Total:
13
13
  %strong
14
- = number_to_currency(Order.find(params[:order_id]).total_price + Order.find(params[:order_id]).delivery.costs)
14
+ = number_to_currency(SimpleCart::Order.find(params[:order_id]).total_price + SimpleCart::Order.find(params[:order_id]).delivery.costs)
@@ -26,7 +26,7 @@
26
26
  .col-md-4.col-sm-4.text-center
27
27
  %h2
28
28
  Order Summary
29
- / = render 'summary'
29
+ = render 'summary'
30
30
 
31
31
  .row
32
32
  .col-md-4.col-sm-4.actions
@@ -33,10 +33,10 @@
33
33
  %li= msg
34
34
 
35
35
  .form-group
36
- - Delivery.all.each do |company|
36
+ - SimpleCart::Delivery.all.each do |company|
37
37
  .radio
38
38
  %label
39
- = f.radio_button :delivery_id, company.id, :checked => company == Delivery.first || @order.delivery == company
39
+ = f.radio_button :delivery_id, company.id, :checked => company == SimpleCart::Delivery.first || @order.delivery == company
40
40
  = "#{company.company}, #{number_to_currency(company.costs)}"
41
41
 
42
42
  .actions
@@ -39,10 +39,10 @@
39
39
  .row
40
40
  .col-xs-6
41
41
  = ff.label :expiration_month
42
- = ff.collection_select :expiration_month, CreditCard.months, :to_s, :to_s, {}, :class => 'form-control'
42
+ = ff.collection_select :expiration_month, SimpleCart::CreditCard.months, :to_s, :to_s, {}, :class => 'form-control'
43
43
  .col-xs-6
44
44
  = ff.label :expiration_year
45
- = ff.collection_select :expiration_year, CreditCard.years, :to_s, :to_s, {}, :class => 'form-control'
45
+ = ff.collection_select :expiration_year, SimpleCart::CreditCard.years, :to_s, :to_s, {}, :class => 'form-control'
46
46
  .form-group
47
47
  = ff.label :cvv
48
48
  .form-inline
@@ -1,6 +1,6 @@
1
- class CreateOrderItem < ActiveRecord::Migration
1
+ class CreateSimpleCartOrderItem < ActiveRecord::Migration
2
2
  def change
3
- create_table "order_items", force: :cascade do |t|
3
+ create_table "simple_cart_order_items", force: :cascade do |t|
4
4
  t.decimal "price"
5
5
  t.integer "qty"
6
6
  t.datetime "created_at", null: false
@@ -10,7 +10,7 @@ class CreateOrderItem < ActiveRecord::Migration
10
10
  t.string "order_id"
11
11
  end
12
12
 
13
- add_index :order_items, :itemable_id
14
- add_index :order_items, :order_id
13
+ add_index :simple_cart_order_items, :itemable_id
14
+ add_index :simple_cart_order_items, :order_id
15
15
  end
16
- end
16
+ end
@@ -1,6 +1,6 @@
1
- class CreateOrder < ActiveRecord::Migration
1
+ class CreateSimpleCartOrder < ActiveRecord::Migration
2
2
  def change
3
- create_table "orders", force: :cascade do |t|
3
+ create_table "simple_cart_orders", force: :cascade do |t|
4
4
  t.decimal "total_price", precision: 10, scale: 2
5
5
  t.date "completed_date"
6
6
  t.datetime "created_at", null: false
@@ -9,4 +9,4 @@ class CreateOrder < ActiveRecord::Migration
9
9
  t.string "aasm_state"
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,6 +1,6 @@
1
- class Address < ActiveRecord::Migration
1
+ class CreateSimpleCartAddress < ActiveRecord::Migration
2
2
  def change
3
- create_table "addresses", force: :cascade do |t|
3
+ create_table "simple_cart_addresses", force: :cascade do |t|
4
4
  t.string "address"
5
5
  t.string "zipcode"
6
6
  t.string "city"
@@ -14,6 +14,6 @@ class Address < ActiveRecord::Migration
14
14
  t.string "type"
15
15
  end
16
16
 
17
- add_index "addresses", ["order_id"], name: "index_addresses_on_order_id"
17
+ add_index "simple_cart_addresses", ["order_id"]
18
18
  end
19
- end
19
+ end
@@ -1,6 +1,6 @@
1
- class Delivery < ActiveRecord::Migration
1
+ class CreateSimpleCartDelivery < ActiveRecord::Migration
2
2
  def change
3
- create_table "deliveries", force: :cascade do |t|
3
+ create_table "simple_cart_deliveries", force: :cascade do |t|
4
4
  t.string "company"
5
5
  t.datetime "created_at", null: false
6
6
  t.datetime "updated_at", null: false
@@ -8,3 +8,4 @@ class Delivery < ActiveRecord::Migration
8
8
  end
9
9
  end
10
10
  end
11
+
@@ -1,6 +1,6 @@
1
- class AddCreditCard < ActiveRecord::Migration
1
+ class CreateSimpleCartCreditCard < ActiveRecord::Migration
2
2
  def change
3
- create_table "credit_cards", force: :cascade do |t|
3
+ create_table "simple_cart_credit_cards", force: :cascade do |t|
4
4
  t.string "number"
5
5
  t.string "cvv"
6
6
  t.string "expiration_year"
@@ -12,6 +12,6 @@ class AddCreditCard < ActiveRecord::Migration
12
12
  t.integer "user_id"
13
13
  t.integer "order_id"
14
14
  end
15
- add_index "credit_cards", ["order_id"], name: "index_credit_cards_on_order_id"
15
+ add_index "simple_cart_credit_cards", ["order_id"]
16
16
  end
17
17
  end
@@ -0,0 +1,10 @@
1
+ class CreateSimpleCartAsdas < ActiveRecord::Migration
2
+ def change
3
+ create_table :simple_cart_asdas do |t|
4
+ t.string :asg
5
+ t.string :asgf
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleCart
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,19 @@
1
- # desc "Explaining what the task does"
2
- # task :simple_cart do
3
- # # Task goes here
4
- # end
1
+ namespace :simple_cart do
2
+ desc "Adding new delivery service to 'deliveries' table. Syntax: 'rake simple_cart:create_delivery [NAME] [COSTS]'"
3
+ task :create_delivery => :environment do
4
+ ARGV.each { |a| task a.to_sym do ; end }
5
+ SimpleCart::Delivery.create(company: ARGV[1], costs: ARGV[2])
6
+ puts "#{ARGV[1]} was successfully added."
7
+ end
8
+
9
+ task :delete_delivery => :environment do
10
+ ARGV.each { |a| task a.to_sym do ; end }
11
+ SimpleCart::Delivery.find_by(company: ARGV[1]).destroy
12
+ end
13
+
14
+ task :delete_all => :environment do
15
+ SimpleCart::Delivery.delete_all
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the things controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -2,6 +2,4 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
-
6
-
7
5
  end
@@ -0,0 +1,58 @@
1
+ class ThingsController < ApplicationController
2
+ before_action :set_thing, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /things
5
+ def index
6
+ @things = Thing.all
7
+ end
8
+
9
+ # GET /things/1
10
+ def show
11
+ end
12
+
13
+ # GET /things/new
14
+ def new
15
+ @thing = Thing.new
16
+ end
17
+
18
+ # GET /things/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /things
23
+ def create
24
+ @thing = Thing.new(thing_params)
25
+
26
+ if @thing.save
27
+ redirect_to @thing, notice: 'Thing was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /things/1
34
+ def update
35
+ if @thing.update(thing_params)
36
+ redirect_to @thing, notice: 'Thing was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /things/1
43
+ def destroy
44
+ @thing.destroy
45
+ redirect_to things_url, notice: 'Thing was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_thing
51
+ @thing = Thing.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def thing_params
56
+ params.require(:thing).permit(:name, :price, :qty)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module ThingsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Thing < ActiveRecord::Base
2
+ end
@@ -1,10 +1,10 @@
1
- <%= form_for(@item) do |f| %>
2
- <% if @item.errors.any? %>
1
+ <%= form_for(@thing) do |f| %>
2
+ <% if @thing.errors.any? %>
3
3
  <div id="error_explanation">
4
- <h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2>
4
+ <h2><%= pluralize(@thing.errors.count, "error") %> prohibited this thing from being saved:</h2>
5
5
 
6
6
  <ul>
7
- <% @item.errors.full_messages.each do |message| %>
7
+ <% @thing.errors.full_messages.each do |message| %>
8
8
  <li><%= message %></li>
9
9
  <% end %>
10
10
  </ul>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Thing</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @thing %> |
6
+ <%= link_to 'Back', things_path %>
@@ -0,0 +1,31 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Listing Things</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Name</th>
9
+ <th>Price</th>
10
+ <th>Qty</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @things.each do |thing| %>
17
+ <tr>
18
+ <td><%= thing.name %></td>
19
+ <td><%= thing.price %></td>
20
+ <td><%= thing.qty %></td>
21
+ <td><%= link_to 'Show', thing %></td>
22
+ <td><%= link_to 'Edit', edit_thing_path(thing) %></td>
23
+ <td><%= link_to 'Destroy', thing, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Thing', new_thing_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Thing</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', things_path %>
@@ -0,0 +1,21 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Name:</strong>
5
+ <%= @thing.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Price:</strong>
10
+ <%= @thing.price %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Qty:</strong>
15
+ <%= @thing.qty %>
16
+ </p>
17
+
18
+ <%= add_to_cart(@thing) %>
19
+
20
+ <%= link_to 'Edit', edit_thing_path(@thing) %> |
21
+ <%= link_to 'Back', things_path %>
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+ resources :things
2
3
  resources :bicycles
3
4
  resources :items
4
5
  mount SimpleCart::Engine => "/simple_cart"
Binary file
@@ -1,7 +1,7 @@
1
1
  # This migration comes from simple_cart (originally 20160312121928)
2
- class CreateOrderItems < ActiveRecord::Migration
2
+ class CreateSimpleCartOrderItem < ActiveRecord::Migration
3
3
  def change
4
- create_table "order_items", force: :cascade do |t|
4
+ create_table "simple_cart_order_items", force: :cascade do |t|
5
5
  t.decimal "price"
6
6
  t.integer "qty"
7
7
  t.datetime "created_at", null: false
@@ -11,7 +11,7 @@ class CreateOrderItems < ActiveRecord::Migration
11
11
  t.string "order_id"
12
12
  end
13
13
 
14
- add_index :order_items, :itemable_id
15
- add_index :order_items, :order_id
14
+ add_index :simple_cart_order_items, :itemable_id
15
+ add_index :simple_cart_order_items, :order_id
16
16
  end
17
- end
17
+ end
@@ -1,13 +1,13 @@
1
1
  # This migration comes from simple_cart (originally 20160312124050)
2
- class CreateOrder < ActiveRecord::Migration
2
+ class CreateSimpleCartOrder < ActiveRecord::Migration
3
3
  def change
4
- create_table "orders", force: :cascade do |t|
4
+ create_table "simple_cart_orders", force: :cascade do |t|
5
5
  t.decimal "total_price", precision: 10, scale: 2
6
6
  t.date "completed_date"
7
7
  t.datetime "created_at", null: false
8
8
  t.datetime "updated_at", null: false
9
- t.integer "shipping_id"
9
+ t.integer "delivery_id"
10
10
  t.string "aasm_state"
11
11
  end
12
12
  end
13
- end
13
+ end