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.
- checksums.yaml +4 -4
- data/app/models/simple_cart/address.rb +12 -0
- data/app/models/simple_cart/asda.rb +4 -0
- data/app/models/simple_cart/billing_address.rb +4 -0
- data/app/models/simple_cart/cart.rb +74 -0
- data/app/models/simple_cart/credit_card.rb +24 -0
- data/app/models/simple_cart/delivery.rb +6 -0
- data/app/models/simple_cart/order.rb +60 -0
- data/app/models/simple_cart/order_item.rb +6 -0
- data/app/models/simple_cart/shipping_address.rb +4 -0
- data/app/views/simple_cart/checkout/_address.html.haml +1 -1
- data/app/views/simple_cart/checkout/_summary.html.haml +4 -4
- data/app/views/simple_cart/checkout/billing.html.haml +1 -1
- data/app/views/simple_cart/checkout/delivery.html.haml +2 -2
- data/app/views/simple_cart/checkout/payment.html.haml +2 -2
- data/db/migrate/{20160312121928_create_order_item.rb → 20160312121928_create_simple_cart_order_item.rb} +5 -5
- data/db/migrate/{20160312124050_create_order.rb → 20160312124050_create_simple_cart_order.rb} +3 -3
- data/db/migrate/{20160312142534_address.rb → 20160312142534_create_simple_cart_address.rb} +4 -4
- data/db/migrate/{20160312145452_delivery.rb → 20160312145452_create_simple_cart_delivery.rb} +3 -2
- data/db/migrate/{20160312151237_add_credit_card.rb → 20160312151237_create_simple_cart_credit_card.rb} +3 -3
- data/db/migrate/20160314183842_create_simple_cart_asdas.rb +10 -0
- data/lib/simple_cart/version.rb +1 -1
- data/lib/tasks/simple_cart_tasks.rake +19 -4
- data/test/dummy/app/assets/javascripts/things.js +2 -0
- data/test/dummy/app/assets/stylesheets/things.scss +3 -0
- data/test/dummy/app/controllers/application_controller.rb +0 -2
- data/test/dummy/app/controllers/things_controller.rb +58 -0
- data/test/dummy/app/helpers/things_helper.rb +2 -0
- data/test/dummy/app/models/thing.rb +2 -0
- data/test/dummy/app/views/{items → things}/_form.html.erb +4 -4
- data/test/dummy/app/views/things/edit.html.erb +6 -0
- data/test/dummy/app/views/things/index.html.erb +31 -0
- data/test/dummy/app/views/things/new.html.erb +5 -0
- data/test/dummy/app/views/things/show.html.erb +21 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/{20160312124601_create_order_items.simple_cart.rb → 20160314184432_create_simple_cart_order_item.simple_cart.rb} +5 -5
- data/test/dummy/db/migrate/{20160312124602_create_order.simple_cart.rb → 20160314184433_create_simple_cart_order.simple_cart.rb} +4 -4
- data/test/dummy/db/migrate/{20160312142752_address.simple_cart.rb → 20160314184434_create_simple_cart_address.simple_cart.rb} +4 -4
- data/test/dummy/db/migrate/{20160312145636_delivery.simple_cart.rb → 20160314184435_create_simple_cart_delivery.simple_cart.rb} +3 -2
- data/test/dummy/db/migrate/{20160312151409_add_credit_card.simple_cart.rb → 20160314184436_create_simple_cart_credit_card.simple_cart.rb} +3 -3
- data/test/dummy/db/migrate/20160314184437_create_simple_cart_asdas.simple_cart.rb +11 -0
- data/test/dummy/db/migrate/{20160307150139_create_items.rb → 20160314184745_create_things.rb} +2 -2
- data/test/dummy/db/schema.rb +21 -29
- data/test/dummy/log/development.log +3814 -0
- data/test/dummy/test/controllers/things_controller_test.rb +49 -0
- data/test/dummy/test/models/{item_test.rb → thing_test.rb} +1 -1
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/-sMBlUbMCruloZiGwXAkZ5qkMXnSOfizEHh42yfICOo.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/2do6_0BJY_m-WISNQO55OL7r8EryK6F5GT875Vmdr_I.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/6rr48iVYpUE7q2m5J4DGmbU2hoaoT94T1TKw0hx2MgU.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/83NGEE7Dkkuzj_aphqH3WxVn5hHfKVawDdEztQSpGF8.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/8DXxFxOs3XK06Mxa2Ob19isXxUDJ28PqKZkHvaWv75Y.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/AYBEyhZJ0H2jvcUYmWfnUsg-5ecns9BP_8fxyreMlek.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/BgsENjJNIUiGA7nr7BkOYU8zcNW6XeB6BNNv4MWjWaQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Cl6gPwmWN2Yt_JZfRenwju2AwmuvMazp847XaP4iwOU.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/DSOLSc6A5RVSmvM415eEWAWG_AgOvZcLZOXQjsXyWQA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/EsPwaYrEK5VY70wbjmozW82BnI3AeMHHznHT1y4or0s.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/I7zER_NAw46Rh3MUqyIlZQcYUzI_b9jGGDuf8unwfAA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/LuVuixjEF7YqVs6naYiDzEQs17oZrgPjH7xBIna-dFk.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/N3ynYTk1iq-DkvgrkhdDk2fFBaCqcroKAfKK0fOuq4M.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/QmeozvaJCXEZgrsu54HdlAztW40N4GgOr5Euwv1_b6I.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Rj42BFwHvQpHPnt1iAOPi89OYrjqGtGG_4wceo2BBJU.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/XnsVm-Zv77KyLk_T1Ir1BbtWmQONMpeQ8oFiw0youEs.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/XpaMhBmfnKXevKG9G3pnDyi2I__eqrtiSScrPOQISJQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Z0hYz4kAc0qIHZh2B6PKbQzGp-o9iOHeG4p6UZ5I79g.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Z2uWpFgWmN5mCkSLFelYcIHrd3Hg_jZvl3OToBURIx0.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/ZE1rEtR4O5c-wrMABt6kf3KPw9ANKgCvDLl_HKA67tw.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/_lZdgp3oIruAKbhu6WtQOSgdulGjDuxwvsZYlqQhvgs.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/a-QY9no1r9wESk0XVZMU9-j4ILaT0dYl4wZXDp81u-Y.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/bGACHbYazmadJKSmeRj-qOtfk2VhzZVNcCtZeJjWdnQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/gZp3uXMHuYQC4hzCr7bQfetKNdJAtbQmg3so2KpW1Dw.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/ibD5UKGyxBi5Ku5BUV1vG7rslb0drFn8WSbtt5IIUjI.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/kQrLKly_-oWaLlXxLU1kJ_f2RGKSegikbCSLB6ngQb0.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/lK1OKrUN4Aa4ULF5iC8LIO9b_8pD6VtM7QmFoR_Hyq4.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/nwZ7OlaT5CopAytu4Wj7C2dIhJATxQcr9-llmxhvr24.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/qEqxPoB4kreE79i9bMtvzfKkwN0k6R3RiGyGNqfu3hg.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/qWFB2-t9pKzO4Y2L9nrDJ--Il_NK1G6W1VTOZmp7NEU.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/rX4eaTmGdGCEW9N1MaxQaGYQf6Ai9y7fx-tYKEkWKSg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/tC2-EIZv61P8CEFijr9uxHBmHtSivZyE-y3KOR5Th7k.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/upXyvpsevxXjLhjtNkXE1yKW2WpRPLP3icept_dAfDc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/vo2uJ1UBvSksPJ8Tv0I29pH8zcKe_PwMZa2RIXHCyfU.cache +1 -0
- data/test/dummy/tmp/pids/server.pid +1 -1
- data/test/{dummy/test/fixtures/items.yml → fixtures/simple_cart/asdas.yml} +4 -6
- data/test/fixtures/simple_cart/sssses.yml +11 -0
- data/test/fixtures/simple_cart/tests.yml +11 -0
- data/test/models/simple_cart/asda_test.rb +9 -0
- data/test/models/simple_cart/ssss_test.rb +9 -0
- data/test/models/simple_cart/test_test.rb +9 -0
- metadata +164 -101
- data/README.rdoc +0 -3
- data/app/models/address.rb +0 -10
- data/app/models/billing_address.rb +0 -2
- data/app/models/cart.rb +0 -71
- data/app/models/credit_card.rb +0 -22
- data/app/models/delivery.rb +0 -4
- data/app/models/order.rb +0 -58
- data/app/models/order_item.rb +0 -4
- data/app/models/shipping_address.rb +0 -2
- data/test/dummy/app/models/bicycle.rb +0 -2
- data/test/dummy/app/models/coupon.rb +0 -2
- data/test/dummy/app/models/item.rb +0 -2
- data/test/dummy/app/views/bicycles/_form.html.erb +0 -29
- data/test/dummy/app/views/bicycles/edit.html.erb +0 -6
- data/test/dummy/app/views/bicycles/index.html.erb +0 -31
- data/test/dummy/app/views/bicycles/new.html.erb +0 -5
- data/test/dummy/app/views/bicycles/show.html.erb +0 -21
- data/test/dummy/app/views/items/edit.html.erb +0 -6
- data/test/dummy/app/views/items/index.html.erb +0 -31
- data/test/dummy/app/views/items/new.html.erb +0 -5
- data/test/dummy/app/views/items/show.html.erb +0 -25
- data/test/dummy/db/migrate/20160310215421_create_bicycles.rb +0 -11
- data/test/dummy/db/migrate/20160310231528_create_coupons.rb +0 -10
- data/test/dummy/db/migrate/20160312142751_create_order_item.simple_cart.rb +0 -17
- data/test/dummy/db/migrate/20160312151033_fix.simple_cart.rb +0 -6
- data/test/dummy/test/models/bicycle_test.rb +0 -7
- /data/test/dummy/app/views/layouts/{application2.html.erb → application.html.erb} +0 -0
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6148409ab1f3ae853be9e98ba3f16af6d0240b0e
|
4
|
+
data.tar.gz: fced1198da49b7cf588d8526a6ab3b8e3aa5769f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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,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
|
@@ -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)
|
@@ -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
|
1
|
+
class CreateSimpleCartOrderItem < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table "
|
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 :
|
14
|
-
add_index :
|
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
|
data/db/migrate/{20160312124050_create_order.rb → 20160312124050_create_simple_cart_order.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class CreateSimpleCartOrder < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table "
|
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
|
1
|
+
class CreateSimpleCartAddress < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table "
|
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 "
|
17
|
+
add_index "simple_cart_addresses", ["order_id"]
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
data/db/migrate/{20160312145452_delivery.rb → 20160312145452_create_simple_cart_delivery.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class CreateSimpleCartDelivery < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table "
|
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
|
1
|
+
class CreateSimpleCartCreditCard < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table "
|
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 "
|
15
|
+
add_index "simple_cart_credit_cards", ["order_id"]
|
16
16
|
end
|
17
17
|
end
|
data/lib/simple_cart/version.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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,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
|
@@ -1,10 +1,10 @@
|
|
1
|
-
<%= form_for(@
|
2
|
-
<% if @
|
1
|
+
<%= form_for(@thing) do |f| %>
|
2
|
+
<% if @thing.errors.any? %>
|
3
3
|
<div id="error_explanation">
|
4
|
-
<h2><%= pluralize(@
|
4
|
+
<h2><%= pluralize(@thing.errors.count, "error") %> prohibited this thing from being saved:</h2>
|
5
5
|
|
6
6
|
<ul>
|
7
|
-
<% @
|
7
|
+
<% @thing.errors.full_messages.each do |message| %>
|
8
8
|
<li><%= message %></li>
|
9
9
|
<% end %>
|
10
10
|
</ul>
|
@@ -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,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 %>
|
data/test/dummy/config/routes.rb
CHANGED
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This migration comes from simple_cart (originally 20160312121928)
|
2
|
-
class
|
2
|
+
class CreateSimpleCartOrderItem < ActiveRecord::Migration
|
3
3
|
def change
|
4
|
-
create_table "
|
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 :
|
15
|
-
add_index :
|
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
|
2
|
+
class CreateSimpleCartOrder < ActiveRecord::Migration
|
3
3
|
def change
|
4
|
-
create_table "
|
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 "
|
9
|
+
t.integer "delivery_id"
|
10
10
|
t.string "aasm_state"
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|