effective_orders 2.2.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +124 -84
- data/app/assets/javascripts/effective_orders/customers.js.coffee +39 -0
- data/app/assets/javascripts/effective_orders/providers/{stripe_charges.js.coffee → stripe.js.coffee} +15 -13
- data/app/assets/javascripts/effective_orders/subscriptions.js.coffee +73 -0
- data/app/assets/stylesheets/effective_orders.scss +2 -1
- data/app/assets/stylesheets/effective_orders/_order.scss +16 -8
- data/app/assets/stylesheets/effective_orders/_subscriptions.scss +14 -0
- data/app/controllers/admin/customers_controller.rb +11 -8
- data/app/controllers/admin/order_items_controller.rb +4 -8
- data/app/controllers/admin/orders_controller.rb +133 -87
- data/app/controllers/effective/carts_controller.rb +18 -8
- data/app/controllers/effective/concerns/purchase.rb +39 -0
- data/app/controllers/effective/customers_controller.rb +43 -0
- data/app/controllers/effective/orders_controller.rb +73 -119
- data/app/controllers/effective/providers/app_checkout.rb +3 -1
- data/app/controllers/effective/providers/ccbill.rb +4 -6
- data/app/controllers/effective/providers/cheque.rb +20 -11
- data/app/controllers/effective/providers/free.rb +33 -0
- data/app/controllers/effective/providers/mark_as_paid.rb +33 -0
- data/app/controllers/effective/providers/moneris.rb +9 -17
- data/app/controllers/effective/providers/paypal.rb +4 -6
- data/app/controllers/effective/providers/pretend.rb +4 -4
- data/app/controllers/effective/providers/refund.rb +39 -0
- data/app/controllers/effective/providers/stripe.rb +19 -40
- data/app/controllers/effective/providers/stripe_connect.rb +2 -6
- data/app/controllers/effective/webhooks_controller.rb +44 -95
- data/app/datatables/effective_customers_datatable.rb +21 -29
- data/app/datatables/effective_order_items_datatable.rb +77 -79
- data/app/datatables/effective_orders_datatable.rb +67 -57
- data/app/helpers/effective_carts_helper.rb +17 -14
- data/app/helpers/effective_orders_helper.rb +40 -56
- data/app/helpers/effective_paypal_helper.rb +3 -3
- data/app/helpers/effective_stripe_helper.rb +47 -18
- data/app/helpers/effective_subscriptions_helper.rb +79 -0
- data/app/mailers/effective/orders_mailer.rb +125 -2
- data/app/models/concerns/acts_as_purchasable.rb +23 -33
- data/app/models/concerns/acts_as_subscribable.rb +68 -0
- data/app/models/concerns/acts_as_subscribable_buyer.rb +22 -0
- data/app/models/effective/cart.rb +53 -24
- data/app/models/effective/cart_item.rb +6 -12
- data/app/models/effective/customer.rb +51 -54
- data/app/models/effective/order.rb +160 -147
- data/app/models/effective/order_item.rb +18 -21
- data/app/models/effective/product.rb +7 -7
- data/app/models/effective/providers/ccbill_postback.rb +1 -1
- data/app/models/effective/providers/stripe_charge.rb +8 -19
- data/app/models/effective/subscripter.rb +230 -0
- data/app/models/effective/subscription.rb +27 -76
- data/app/models/effective/tax_rate_calculator.rb +10 -7
- data/app/views/admin/customers/_actions.html.haml +1 -2
- data/app/views/admin/customers/index.html.haml +1 -1
- data/app/views/admin/customers/show.html.haml +6 -0
- data/app/views/admin/orders/_actions.html.haml +9 -7
- data/app/views/admin/orders/_form.html.haml +11 -7
- data/app/views/admin/orders/_order_actions.html.haml +2 -1
- data/app/views/admin/orders/_order_item_fields.html.haml +1 -1
- data/app/views/admin/orders/edit.html.haml +4 -0
- data/app/views/admin/orders/index.html.haml +1 -4
- data/app/views/admin/orders/new.html.haml +1 -1
- data/app/views/admin/orders/show.html.haml +5 -6
- data/app/views/effective/carts/_cart.html.haml +2 -2
- data/app/views/effective/carts/show.html.haml +2 -2
- data/app/views/effective/customers/_customer.html.haml +152 -0
- data/app/views/effective/customers/_fields.html.haml +12 -0
- data/app/views/effective/customers/_form.html.haml +13 -0
- data/app/views/effective/customers/edit.html.haml +3 -0
- data/app/views/effective/orders/_checkout_step1.html.haml +8 -15
- data/app/views/effective/orders/_checkout_step2.html.haml +34 -21
- data/app/views/effective/orders/_order.html.haml +8 -9
- data/app/views/effective/orders/_order_actions.html.haml +7 -8
- data/app/views/effective/orders/_order_header.html.haml +1 -1
- data/app/views/effective/orders/_order_items.html.haml +11 -5
- data/app/views/effective/orders/_order_note.html.haml +4 -7
- data/app/views/effective/orders/_orders_table.html.haml +26 -26
- data/app/views/effective/orders/app_checkout/_form.html.haml +2 -2
- data/app/views/effective/orders/ccbill/_form.html.haml +1 -1
- data/app/views/effective/orders/cheque/_form.html.haml +3 -1
- data/app/views/effective/orders/declined.html.haml +1 -1
- data/app/views/effective/orders/{checkout_step1.html.haml → edit.html.haml} +0 -0
- data/app/views/effective/orders/free/_form.html.haml +4 -0
- data/app/views/effective/orders/index.html.haml +2 -4
- data/app/views/effective/orders/mark_as_paid/_form.html.haml +32 -0
- data/app/views/effective/orders/moneris/_form.html.haml +6 -6
- data/app/views/effective/orders/{checkout_step2.html.haml → new.html.haml} +1 -1
- data/app/views/effective/orders/paypal/_form.html.haml +2 -2
- data/app/views/effective/orders/pretend/_form.html.haml +2 -2
- data/app/views/effective/orders/purchased.html.haml +3 -0
- data/app/views/effective/orders/refund/_form.html.haml +32 -0
- data/app/views/effective/orders/show.html.haml +4 -1
- data/app/views/effective/orders/stripe/_form.html.haml +5 -5
- data/app/views/effective/orders_mailer/subscription_canceled.html.haml +9 -0
- data/app/views/effective/orders_mailer/subscription_payment_failed.html.haml +9 -0
- data/app/views/effective/orders_mailer/subscription_payment_succeeded.html.haml +9 -0
- data/app/views/effective/orders_mailer/subscription_trial_expired.html.haml +5 -0
- data/app/views/effective/orders_mailer/subscription_trial_expiring.html.haml +7 -0
- data/app/views/effective/subscriptions/_fields.html.haml +16 -0
- data/app/views/effective/subscriptions/_plan.html.haml +21 -0
- data/app/views/layouts/effective_orders_mailer_layout.html.haml +6 -8
- data/config/effective_orders.rb +41 -20
- data/config/routes.rb +48 -48
- data/db/migrate/01_create_effective_orders.rb.erb +19 -5
- data/lib/effective_orders.rb +78 -42
- data/lib/effective_orders/engine.rb +36 -82
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +2 -2
- data/lib/generators/templates/effective_orders_mailer_preview.rb +39 -4
- data/lib/tasks/effective_orders_tasks.rake +42 -0
- data/spec/controllers/carts_controller_spec.rb +1 -1
- data/spec/controllers/moneris_orders_controller_spec.rb +4 -4
- data/spec/controllers/orders_controller_spec.rb +4 -4
- data/spec/controllers/stripe_orders_controller_spec.rb +2 -2
- data/spec/controllers/webhooks_controller_spec.rb +1 -1
- data/spec/dummy/config/initializers/effective_orders.rb +1 -7
- data/spec/dummy/db/schema.rb +1 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +3 -0
- data/spec/models/acts_as_purchasable_spec.rb +0 -56
- data/spec/models/customer_spec.rb +3 -3
- data/spec/models/order_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/factories.rb +2 -1
- metadata +37 -49
- data/active_admin/effective_carts.rb +0 -14
- data/active_admin/effective_orders.rb +0 -112
- data/app/assets/javascripts/effective_orders/providers/stripe_subscriptions.js.coffee +0 -28
- data/app/controllers/concerns/acts_as_active_admin_controller.rb +0 -69
- data/app/controllers/effective/subscriptions_controller.rb +0 -126
- data/app/models/effective/datatables/customers.rb +0 -40
- data/app/models/effective/datatables/order_items.rb +0 -101
- data/app/models/effective/datatables/orders.rb +0 -91
- data/app/models/inputs/price_field.rb +0 -63
- data/app/models/inputs/price_form_input.rb +0 -7
- data/app/models/inputs/price_formtastic_input.rb +0 -9
- data/app/models/inputs/price_input.rb +0 -19
- data/app/models/inputs/price_simple_form_input.rb +0 -8
- data/app/views/admin/orders/_form_mark_as_paid.html.haml +0 -33
- data/app/views/admin/orders/_order_payment_details.html.haml +0 -5
- data/app/views/admin/orders/mark_as_paid.html.haml +0 -7
- data/app/views/effective/orders/stripe/_subscription_fields.html.haml +0 -7
- data/app/views/effective/subscriptions/index.html.haml +0 -22
- data/app/views/effective/subscriptions/new.html.haml +0 -9
- data/app/views/effective/subscriptions/show.html.haml +0 -49
- data/db/upgrade/02_upgrade_effective_orders_from03x.rb.erb +0 -29
- data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +0 -98
- data/db/upgrade/upgrade_price_column_on_table.rb.erb +0 -17
- data/lib/generators/effective_orders/upgrade_from03x_generator.rb +0 -31
- data/lib/generators/effective_orders/upgrade_from1x_generator.rb +0 -27
- data/lib/generators/effective_orders/upgrade_price_column_generator.rb +0 -30
@@ -1,38 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
datatable do
|
4
|
-
order :email
|
1
|
+
class EffectiveCustomersDatatable < Effective::Datatable
|
2
|
+
datatable do
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
mail_to user.email, user.email
|
9
|
-
end
|
4
|
+
col :id, visible: false
|
5
|
+
#col 'user.email'
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if EffectiveOrders.stripe_connect_enabled
|
17
|
-
col :stripe_connect_access_token
|
18
|
-
end
|
19
|
-
|
20
|
-
col :subscription_types, sql_column: 'subscription_types'
|
7
|
+
if EffectiveOrders.stripe_enabled
|
8
|
+
col :stripe_customer_id
|
9
|
+
col :active_card
|
10
|
+
end
|
21
11
|
|
22
|
-
|
12
|
+
if EffectiveOrders.stripe_connect_enabled
|
13
|
+
col :stripe_connect_access_token
|
23
14
|
end
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
.joins(:user, :subscriptions)
|
28
|
-
.select('customers.*, users.email AS email')
|
29
|
-
.select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
|
30
|
-
.group('customers.id, subscriptions.stripe_plan_id, users.email')
|
16
|
+
actions_col do |customer|
|
17
|
+
link_to('Manage', "https://dashboard.stripe.com/#{'test/' if Rails.env.development?}customers/#{customer.stripe_customer_id}")
|
31
18
|
end
|
32
19
|
|
33
|
-
# def search_column(collection, table_column, search_term)
|
34
|
-
# return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
|
35
|
-
# super
|
36
|
-
# end
|
37
20
|
end
|
21
|
+
|
22
|
+
collection do
|
23
|
+
Effective::Customer.joins(:user).all
|
24
|
+
end
|
25
|
+
|
26
|
+
# def search_column(collection, table_column, search_term)
|
27
|
+
# return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
|
28
|
+
# super
|
29
|
+
# end
|
38
30
|
end
|
@@ -1,101 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
order :purchased_at, :desc
|
1
|
+
class EffectiveOrderItemsDatatable < Effective::Datatable
|
2
|
+
datatable do
|
3
|
+
order :purchased_at, :desc
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
col(:purchased_at, sql_column: 'orders.purchased_at') do |order_item|
|
6
|
+
Time.at(order_item[:purchased_at]).in_time_zone if order_item[:purchased_at].present?
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
col :order
|
13
|
-
|
14
|
-
# if effectiveorders.obfuscate_order_ids
|
15
|
-
# col(:order, type: :obfuscated_id) do |order_item|
|
16
|
-
# obfuscated_id = effective::order.obfuscate(order_item[:order_id])
|
17
|
-
# link_to(obfuscated_id, (datatables_admin_path? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
18
|
-
# end
|
19
|
-
# else
|
20
|
-
# col(:order) do |order_item|
|
21
|
-
# link_to(order_item.to_param, (datatables_admin_path? ? effective_orders.admin_order_path(order_item.to_param) : effective_orders.order_path(order_item.to_param)))
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
|
25
|
-
unless attributes[:user_id]
|
26
|
-
col :email, sql_column: 'users.email', label: 'Buyer Email' do |order_item|
|
27
|
-
link_to order_item[:email], (edit_admin_user_path(order_item[:user_id]) rescue admin_user_path(order_item[:user_id]) rescue '#')
|
28
|
-
end
|
29
|
-
end
|
9
|
+
col :id, visible: false
|
30
10
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
11
|
+
col :order
|
12
|
+
|
13
|
+
# if effectiveorders.obfuscate_order_ids
|
14
|
+
# col(:order, type: :obfuscated_id) do |order_item|
|
15
|
+
# obfuscated_id = effective::order.obfuscate(order_item[:order_id])
|
16
|
+
# link_to(obfuscated_id, (datatables_admin_path? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
17
|
+
# end
|
18
|
+
# else
|
19
|
+
# col(:order) do |order_item|
|
20
|
+
# link_to(order_item.to_param, (datatables_admin_path? ? effective_orders.admin_order_path(order_item.to_param) : effective_orders.order_path(order_item.to_param)))
|
21
|
+
# end
|
22
|
+
# end
|
36
23
|
|
37
|
-
|
38
|
-
|
24
|
+
unless attributes[:user_id]
|
25
|
+
col :email, sql_column: 'users.email', label: 'Buyer Email' do |order_item|
|
26
|
+
link_to order_item[:email], (edit_admin_user_path(order_item[:user_id]) rescue admin_user_path(order_item[:user_id]) rescue '#')
|
39
27
|
end
|
28
|
+
end
|
40
29
|
|
41
|
-
|
42
|
-
|
30
|
+
if EffectiveOrders.require_billing_address && attributes[:user_id].blank?
|
31
|
+
col :buyer_name, sort: false, label: 'Buyer Name' do |order_item|
|
32
|
+
(order_item[:buyer_name] || '').split('!!SEP!!').find(&:present?)
|
43
33
|
end
|
34
|
+
end
|
44
35
|
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
col :purchase_state, sql_column: 'orders.purchase_state', search: { collection: [%w(abandoned abandoned), [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], selected: EffectiveOrders::PURCHASED } do |order_item|
|
37
|
+
order_item[:purchase_state] || 'abandoned'
|
38
|
+
end
|
48
39
|
|
49
|
-
|
50
|
-
|
40
|
+
col :title do |order_item|
|
41
|
+
order_item.quantity == 1 ? order_item.title : "#{order_item.title} (#{order_item.quantity} purchased)"
|
51
42
|
end
|
52
43
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
.select('order_items.*, orders.*, users.email AS email')
|
57
|
-
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
58
|
-
.group('order_items.id, orders.id, users.email')
|
44
|
+
# col :subtotal, as: :price
|
45
|
+
# col :tax, as: :price
|
46
|
+
# col :total, as: :price
|
59
47
|
|
60
|
-
|
61
|
-
|
48
|
+
col :created_at, visible: false
|
49
|
+
col :updated_at, visible: false
|
50
|
+
end
|
62
51
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
collection do
|
53
|
+
collection = Effective::OrderItem.unscoped
|
54
|
+
.joins(order: :user)
|
55
|
+
.select('order_items.*, orders.*, users.email AS email')
|
56
|
+
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
57
|
+
.group('order_items.id, orders.id, users.email')
|
68
58
|
|
69
|
-
|
70
|
-
|
59
|
+
if EffectiveOrders.require_billing_address && defined?(EffectiveAddresses)
|
60
|
+
addresses_tbl = EffectiveAddresses.addresses_table_name
|
71
61
|
|
72
|
-
|
73
|
-
|
62
|
+
collection = collection
|
63
|
+
.joins("LEFT JOIN (SELECT addressable_id, string_agg(#{addresses_tbl}.full_name, '!!SEP!!') AS buyer_name FROM #{addresses_tbl} WHERE #{addresses_tbl}.category = 'billing' AND #{addresses_tbl}.addressable_type = 'Effective::Order' GROUP BY #{addresses_tbl}.addressable_id) #{addresses_tbl} ON orders.id = #{addresses_tbl}.addressable_id")
|
64
|
+
.group("#{addresses_tbl}.buyer_name")
|
65
|
+
.select("#{addresses_tbl}.buyer_name AS buyer_name")
|
74
66
|
end
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
68
|
+
attributes[:user_id].present? ? collection.where("#{EffectiveOrders.orders_table_name.to_s}.user_id = ?", attributes[:user_id]) : collection
|
69
|
+
end
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
def query_subtotal
|
72
|
+
'SUM(price * quantity)'
|
73
|
+
end
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# elsif table_column[:name] == 'purchase_state' && search_term == 'abandoned'
|
88
|
-
# collection.where("#{EffectiveOrders.orders_table_name.to_s}.purchase_state IS NULL")
|
89
|
-
# elsif table_column[:name] == 'subtotal'
|
90
|
-
# collection.having("#{query_subtotal} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
91
|
-
# elsif table_column[:name] == 'tax'
|
92
|
-
# collection.having("#{query_tax} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
93
|
-
# elsif table_column[:name] == 'total'
|
94
|
-
# collection.having("#{query_total} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
95
|
-
# else
|
96
|
-
# super
|
97
|
-
# end
|
98
|
-
# end
|
75
|
+
def query_total
|
76
|
+
'SUM((price * quantity) + (CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END))'
|
77
|
+
end
|
99
78
|
|
79
|
+
def query_tax
|
80
|
+
'(CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END)'
|
100
81
|
end
|
82
|
+
|
83
|
+
# def search_column(collection, table_column, search_term)
|
84
|
+
# if table_column[:name] == 'order'
|
85
|
+
# collection.where("#{EffectiveOrders.order_items_table_name.to_s}.order_id = ?", Effective::Order.deobfuscate(search_term))
|
86
|
+
# elsif table_column[:name] == 'purchase_state' && search_term == 'abandoned'
|
87
|
+
# collection.where("#{EffectiveOrders.orders_table_name.to_s}.purchase_state IS NULL")
|
88
|
+
# elsif table_column[:name] == 'subtotal'
|
89
|
+
# collection.having("#{query_subtotal} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
90
|
+
# elsif table_column[:name] == 'tax'
|
91
|
+
# collection.having("#{query_tax} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
92
|
+
# elsif table_column[:name] == 'total'
|
93
|
+
# collection.having("#{query_total} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
94
|
+
# else
|
95
|
+
# super
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
|
101
99
|
end
|
@@ -1,81 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class EffectiveOrdersDatatable < Effective::Datatable
|
2
|
+
bulk_actions do
|
3
|
+
if EffectiveOrders.authorized?(view.controller, :admin, :effective_orders)
|
4
|
+
bulk_action(
|
5
|
+
'Send payment request email to selected pending orders',
|
6
|
+
effective_orders.bulk_send_payment_request_admin_orders_path,
|
7
|
+
data: { confirm: 'Send payment request emails to pending orders?' }
|
8
|
+
)
|
9
|
+
end
|
5
10
|
|
6
|
-
|
11
|
+
bulk_action(
|
12
|
+
'Send receipt email to selected purchased orders',
|
13
|
+
effective_orders.bulk_send_buyer_receipt_orders_path,
|
14
|
+
data: { confirm: 'Send receipt emails to purchased orders?' }
|
15
|
+
)
|
16
|
+
end
|
7
17
|
|
8
|
-
|
18
|
+
datatable do
|
19
|
+
order :created_at, :desc
|
9
20
|
|
10
|
-
|
11
|
-
col :user, label: 'Buyer', search: :string, sort: :email do |order|
|
12
|
-
link_to order.user.email, (edit_admin_user_path(order.user) rescue admin_user_path(order.user) rescue '#')
|
13
|
-
end
|
21
|
+
bulk_actions_col
|
14
22
|
|
15
|
-
|
16
|
-
val :buyer_name, visible: false do |order|
|
17
|
-
order.billing_address.try(:full_name)
|
18
|
-
end
|
19
|
-
else
|
20
|
-
val :buyer_name, visible: false do |order|
|
21
|
-
order.user.to_s
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
23
|
+
col :purchased_at
|
25
24
|
|
26
|
-
|
27
|
-
col :billing_address
|
28
|
-
end
|
25
|
+
col :id
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
if attributes[:user_id].blank?
|
28
|
+
col :user, label: 'Buyer', search: :string, sort: :email do |order|
|
29
|
+
link_to order.user.email, (edit_admin_user_path(order.user) rescue admin_user_path(order.user) rescue '#')
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
if EffectiveOrders.require_billing_address && EffectiveOrders.use_address_full_name
|
33
|
+
val :buyer_name, visible: false do |order|
|
34
|
+
order.billing_address.try(:full_name)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
val :buyer_name, visible: false do |order|
|
38
|
+
order.user.to_s
|
39
|
+
end
|
36
40
|
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if EffectiveOrders.require_billing_address
|
44
|
+
col :billing_address
|
45
|
+
end
|
37
46
|
|
38
|
-
|
47
|
+
if EffectiveOrders.require_shipping_address
|
48
|
+
col :shipping_address
|
49
|
+
end
|
39
50
|
|
40
|
-
|
41
|
-
|
51
|
+
col :purchase_state, label: 'State', search: { collection: EffectiveOrders::PURCHASE_STATES.invert } do |order|
|
52
|
+
EffectiveOrders::PURCHASE_STATES[order.purchase_state]
|
53
|
+
end
|
42
54
|
|
43
|
-
|
44
|
-
tax_rate_to_percentage(order.tax_rate)
|
45
|
-
end
|
55
|
+
col :order_items, search: { as: :string }
|
46
56
|
|
47
|
-
|
57
|
+
col :subtotal, as: :price
|
58
|
+
col :tax, as: :price
|
48
59
|
|
49
|
-
|
50
|
-
|
60
|
+
col :tax_rate, visible: false do |order|
|
61
|
+
tax_rate_to_percentage(order.tax_rate)
|
62
|
+
end
|
51
63
|
|
52
|
-
|
53
|
-
col :note_to_buyer, visible: false
|
54
|
-
col :note_internal, visible: false
|
64
|
+
col :total, as: :price
|
55
65
|
|
56
|
-
|
57
|
-
|
66
|
+
col :payment_provider, label: 'Provider', visible: false, search: { collection: ['nil'] + (EffectiveOrders.payment_providers + EffectiveOrders.other_payment_providers).sort }
|
67
|
+
col :payment_card, label: 'Card'
|
58
68
|
|
59
|
-
|
60
|
-
|
69
|
+
col :note, visible: false
|
70
|
+
col :note_to_buyer, visible: false
|
71
|
+
col :note_internal, visible: false
|
61
72
|
|
62
|
-
|
63
|
-
|
73
|
+
col :created_at, visible: false
|
74
|
+
col :updated_at, visible: false
|
64
75
|
|
65
|
-
|
66
|
-
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
67
|
-
end
|
76
|
+
actions_col partial: 'admin/orders/actions', partial_as: :order
|
68
77
|
|
69
|
-
|
70
|
-
|
78
|
+
aggregate :total
|
79
|
+
end
|
80
|
+
|
81
|
+
collection do
|
82
|
+
scope = Effective::Order.unscoped.includes(:addresses, :order_items, :user)
|
71
83
|
|
72
|
-
|
73
|
-
|
74
|
-
[EffectiveOrders::ABANDONED, nil],
|
75
|
-
[EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED],
|
76
|
-
[EffectiveOrders::DECLINED, EffectiveOrders::DECLINED],
|
77
|
-
[EffectiveOrders::PENDING, EffectiveOrders::PENDING]
|
78
|
-
]
|
84
|
+
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
85
|
+
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
79
86
|
end
|
87
|
+
|
88
|
+
attributes[:user_id].present? ? scope.where(user_id: attributes[:user_id]) : scope
|
80
89
|
end
|
90
|
+
|
81
91
|
end
|
@@ -1,24 +1,27 @@
|
|
1
1
|
module EffectiveCartsHelper
|
2
|
+
# TODO: Consider unique
|
2
3
|
def current_cart(for_user = nil)
|
3
4
|
@cart ||= (
|
4
5
|
user = for_user || (current_user rescue nil) # rescue protects me against Devise not being installed
|
5
6
|
|
6
7
|
if user.present?
|
7
|
-
Effective::Cart.where(
|
8
|
-
if session[:cart].present?
|
9
|
-
session_cart = Effective::Cart.where('user_id IS NULL').where(id: session[:cart]).first
|
8
|
+
user_cart = Effective::Cart.where(user: user).first_or_create
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
user_cart.reload
|
15
|
-
end
|
10
|
+
# Merge session cart into user cart.
|
11
|
+
if session[:cart].present?
|
12
|
+
session_cart = Effective::Cart.where(user: nil).where(id: session[:cart]).first
|
16
13
|
|
17
|
-
|
14
|
+
if session_cart
|
15
|
+
session_cart.cart_items.each { |i| user_cart.add(i.purchasable, quantity: i.quantity, unique: i.unique) }
|
16
|
+
session_cart.destroy
|
18
17
|
end
|
18
|
+
|
19
|
+
session[:cart] = nil
|
19
20
|
end
|
21
|
+
|
22
|
+
user_cart
|
20
23
|
elsif session[:cart].present?
|
21
|
-
Effective::Cart.where(
|
24
|
+
Effective::Cart.where(user_id: nil).where(id: session[:cart]).first_or_create
|
22
25
|
else
|
23
26
|
cart = Effective::Cart.create!
|
24
27
|
session[:cart] = cart.id
|
@@ -42,7 +45,7 @@ module EffectiveCartsHelper
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def link_to_add_to_cart(purchasable, opts = {})
|
45
|
-
raise
|
48
|
+
raise 'expecting an acts_as_purchasable object' unless purchasable.kind_of?(ActsAsPurchasable)
|
46
49
|
|
47
50
|
options = {
|
48
51
|
label: 'Add to Cart',
|
@@ -60,7 +63,7 @@ module EffectiveCartsHelper
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def link_to_remove_from_cart(cart_item, opts = {})
|
63
|
-
raise
|
66
|
+
raise 'expecting an Effective::CartItem object' unless cart_item.kind_of?(Effective::CartItem)
|
64
67
|
|
65
68
|
options = {
|
66
69
|
label: 'Remove',
|
@@ -120,11 +123,11 @@ module EffectiveCartsHelper
|
|
120
123
|
|
121
124
|
def render_cart(cart = nil)
|
122
125
|
cart ||= current_cart
|
123
|
-
render(partial: 'effective/carts/cart', locals: {cart: cart})
|
126
|
+
render(partial: 'effective/carts/cart', locals: { cart: cart })
|
124
127
|
end
|
125
128
|
|
126
129
|
def render_purchasables(*purchasables)
|
127
|
-
render(partial: 'effective/orders/order_items', locals: {order: Effective::Order.new(purchasables)})
|
130
|
+
render(partial: 'effective/orders/order_items', locals: { order: Effective::Order.new(purchasables) })
|
128
131
|
end
|
129
132
|
|
130
133
|
end
|