effective_orders 1.8.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +150 -60
- data/Rakefile +0 -3
- data/active_admin/effective_orders.rb +14 -9
- data/app/assets/javascripts/effective_orders.js +2 -0
- data/app/assets/javascripts/effective_orders/{stripe_charges.js.coffee → providers/stripe_charges.js.coffee} +1 -1
- data/app/assets/javascripts/effective_orders/{stripe_subscriptions.js.coffee → providers/stripe_subscriptions.js.coffee} +1 -1
- data/app/assets/stylesheets/effective_orders/_order.scss +9 -3
- data/app/controllers/admin/orders_controller.rb +87 -3
- data/app/controllers/concerns/acts_as_active_admin_controller.rb +2 -1
- data/app/controllers/effective/carts_controller.rb +4 -2
- data/app/controllers/effective/orders_controller.rb +101 -60
- data/app/controllers/effective/providers/app_checkout.rb +10 -2
- data/app/controllers/effective/providers/ccbill.rb +34 -0
- data/app/controllers/effective/providers/cheque.rb +30 -0
- data/app/controllers/effective/providers/moneris.rb +7 -7
- data/app/controllers/effective/providers/paypal.rb +7 -5
- data/app/controllers/effective/providers/pretend.rb +22 -0
- data/app/controllers/effective/providers/stripe.rb +26 -24
- data/app/controllers/effective/webhooks_controller.rb +1 -1
- data/app/helpers/effective_carts_helper.rb +59 -29
- data/app/helpers/effective_ccbill_helper.rb +25 -0
- data/app/helpers/effective_orders_helper.rb +50 -41
- data/app/helpers/effective_paypal_helper.rb +11 -11
- data/app/mailers/effective/orders_mailer.rb +95 -20
- data/app/models/concerns/acts_as_purchasable.rb +14 -22
- data/app/models/effective/cart.rb +9 -15
- data/app/models/effective/cart_item.rb +15 -13
- data/app/models/effective/customer.rb +9 -9
- data/app/models/effective/datatables/order_items.rb +14 -8
- data/app/models/effective/datatables/orders.rb +56 -69
- data/app/models/effective/order.rb +250 -139
- data/app/models/effective/order_item.rb +23 -16
- data/app/models/effective/product.rb +23 -0
- data/app/models/effective/providers/ccbill_postback.rb +85 -0
- data/app/models/effective/{stripe_charge.rb → providers/stripe_charge.rb} +1 -1
- data/app/models/effective/subscription.rb +16 -12
- data/app/models/effective/tax_rate_calculator.rb +45 -0
- data/app/views/admin/customers/index.html.haml +2 -5
- data/app/views/admin/order_items/index.html.haml +2 -5
- data/app/views/admin/orders/_actions.html.haml +2 -0
- data/app/views/admin/orders/_form.html.haml +28 -0
- data/app/views/admin/orders/_order_item_fields.html.haml +9 -0
- data/app/views/admin/orders/index.html.haml +9 -5
- data/app/views/admin/orders/new.html.haml +3 -0
- data/app/views/effective/carts/_cart.html.haml +3 -12
- data/app/views/effective/carts/_cart_actions.html.haml +4 -0
- data/app/views/effective/carts/show.html.haml +10 -12
- data/app/views/effective/orders/_checkout_step1.html.haml +46 -0
- data/app/views/effective/orders/_checkout_step2.html.haml +33 -0
- data/app/views/effective/orders/_order.html.haml +2 -0
- data/app/views/effective/orders/_order_actions.html.haml +10 -5
- data/app/views/effective/orders/_order_footer.html.haml +1 -0
- data/app/views/effective/orders/_order_items.html.haml +11 -9
- data/app/views/effective/orders/_order_note.html.haml +8 -0
- data/app/views/effective/orders/_order_note_fields.html.haml +5 -0
- data/app/views/effective/orders/_order_shipping.html.haml +4 -4
- data/app/views/effective/orders/_order_user_fields.html.haml +1 -0
- data/app/views/effective/orders/_orders_table.html.haml +27 -0
- data/app/views/effective/orders/ccbill/_form.html.haml +24 -0
- data/app/views/effective/orders/checkout_step1.html.haml +3 -0
- data/app/views/effective/orders/checkout_step2.html.haml +3 -0
- data/app/views/effective/orders/cheque/_form.html.haml +2 -0
- data/app/views/effective/orders/cheque/pay_by_cheque.html.haml +9 -0
- data/app/views/effective/orders/declined.html.haml +4 -2
- data/app/views/effective/orders/my_purchases.html.haml +1 -1
- data/app/views/effective/orders/my_sales.html.haml +1 -1
- data/app/views/effective/orders/purchased.html.haml +3 -2
- data/app/views/effective/orders/show.html.haml +1 -1
- data/app/views/effective/orders/stripe/_form.html.haml +5 -5
- data/app/views/effective/orders_mailer/order_error.html.haml +11 -0
- data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +13 -0
- data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +13 -0
- data/app/views/layouts/effective_orders_mailer_layout.html.haml +7 -7
- data/config/routes.rb +39 -24
- data/db/migrate/01_create_effective_orders.rb.erb +20 -1
- data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +95 -0
- data/lib/effective_orders.rb +67 -9
- data/lib/effective_orders/app_checkout_service.rb +1 -2
- data/lib/effective_orders/engine.rb +46 -14
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from03x_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from1x_generator.rb +31 -0
- data/lib/generators/templates/effective_orders.rb +131 -66
- data/lib/generators/templates/effective_orders_mailer_preview.rb +28 -13
- data/spec/controllers/admin/orders_controller_spec.rb +242 -0
- data/spec/controllers/ccbill_orders_controller_spec.rb +103 -0
- data/spec/controllers/moneris_orders_controller_spec.rb +23 -23
- data/spec/controllers/orders_controller_spec.rb +167 -79
- data/spec/controllers/stripe_orders_controller_spec.rb +7 -7
- data/spec/dummy/app/models/product.rb +0 -8
- data/spec/dummy/app/models/product_with_float_price.rb +0 -8
- data/spec/dummy/app/models/user.rb +2 -19
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/effective_orders.rb +109 -64
- data/spec/dummy/db/schema.rb +15 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +0 -258
- data/spec/models/acts_as_purchasable_spec.rb +8 -6
- data/spec/models/factories_spec.rb +7 -1
- data/spec/models/order_item_spec.rb +1 -1
- data/spec/models/order_spec.rb +165 -46
- data/spec/models/stripe_charge_spec.rb +5 -5
- data/spec/spec_helper.rb +2 -0
- data/spec/support/factories.rb +49 -33
- metadata +47 -64
- data/app/views/effective/orders/_checkout_step_1.html.haml +0 -43
- data/app/views/effective/orders/_checkout_step_2.html.haml +0 -25
- data/app/views/effective/orders/_my_purchases.html.haml +0 -17
- data/app/views/effective/orders/checkout.html.haml +0 -3
- data/app/views/effective/orders/new.html.haml +0 -4
- data/spec/dummy/log/development.log +0 -82
@@ -3,17 +3,25 @@ module Effective
|
|
3
3
|
module AppCheckout
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
included do
|
7
|
+
if defined?(CanCan)
|
8
|
+
skip_authorization_check only: [:app_checkout]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
def app_checkout
|
7
13
|
@order = Order.find(params[:id])
|
8
14
|
checkout = EffectiveOrders.app_checkout[:service].call(order: @order)
|
9
15
|
if checkout.success?
|
10
|
-
order_purchased(payment_details(checkout))
|
16
|
+
order_purchased(details: payment_details(checkout), provider: 'app_checkout', card: 'none')
|
11
17
|
else
|
12
18
|
flash = EffectiveOrders.app_checkout[:declined_flash]
|
13
|
-
order_declined(payment_details(checkout),
|
19
|
+
order_declined(details: payment_details(checkout), message: flash, provider: 'app_checkout', card: 'none')
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
23
|
+
private
|
24
|
+
|
17
25
|
def payment_details(checkout)
|
18
26
|
default = 'App Checkout'
|
19
27
|
if checkout.respond_to?(:payment_details)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Effective
|
2
|
+
module Providers
|
3
|
+
module Ccbill
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
skip_before_filter :verify_authenticity_token, only: [:ccbill_postback]
|
8
|
+
|
9
|
+
if defined?(CanCan)
|
10
|
+
skip_authorization_check only: [:ccbill_postback]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def ccbill_postback
|
15
|
+
postback = Effective::Providers::CcbillPostback.new(params)
|
16
|
+
@order ||= Effective::Order.find(postback.order_id)
|
17
|
+
|
18
|
+
if @order.present? && postback.verified?
|
19
|
+
if @order.purchased?
|
20
|
+
order_purchased(details: postback.order_details, provider: 'ccbill')
|
21
|
+
elsif postback.approval? && postback.matches?(@order)
|
22
|
+
order_purchased(details: postback.order_details, provider: 'ccbill')
|
23
|
+
else
|
24
|
+
order_declined(details: postback.order_details, provider: 'ccbill')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
head(:ok)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Effective
|
2
|
+
module Providers
|
3
|
+
module Cheque
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def pay_by_cheque
|
7
|
+
@order ||= Order.find(params[:id])
|
8
|
+
|
9
|
+
@order.purchase_state = EffectiveOrders::PENDING
|
10
|
+
@order.payment_provider = 'cheque'
|
11
|
+
|
12
|
+
EffectiveOrders.authorized?(self, :update, @order)
|
13
|
+
|
14
|
+
@page_title = 'Payment Required'
|
15
|
+
|
16
|
+
if @order.save
|
17
|
+
@order.send_pending_order_invoice_to_buyer!
|
18
|
+
current_cart.try(:destroy)
|
19
|
+
flash.now[:success] = 'Successfully indicated order will be payed by cheque.'
|
20
|
+
else
|
21
|
+
flash[:danger] = "Unable to save your order: #{@order.errors.full_messages.to_sentence}. Please try again."
|
22
|
+
redirect_to effective_orders.order_path(@order)
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
render 'effective/orders/cheque/pay_by_cheque'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -4,7 +4,7 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
prepend_before_filter :find_authenticity_token_from_moneris, :
|
7
|
+
prepend_before_filter :find_authenticity_token_from_moneris, only: [:moneris_postback]
|
8
8
|
end
|
9
9
|
|
10
10
|
def moneris_postback
|
@@ -17,7 +17,7 @@ module Effective
|
|
17
17
|
declined_redirect_url = params.delete(:rvar_declined_redirect_url)
|
18
18
|
|
19
19
|
if @order.purchased? # Fallback to a success condition of the Order is already purchased
|
20
|
-
order_purchased(params, purchased_redirect_url)
|
20
|
+
order_purchased(details: params, provider: 'moneris', card: params[:card], redirect_url: purchased_redirect_url)
|
21
21
|
return
|
22
22
|
end
|
23
23
|
|
@@ -27,19 +27,19 @@ module Effective
|
|
27
27
|
response_code = verify_params[:response_code].to_i # Sometimes moneris sends us the string 'null'
|
28
28
|
|
29
29
|
if response_code > 0 && response_code < 50 # Less than 50 means a successful validation
|
30
|
-
order_purchased(params.merge(verify_params), purchased_redirect_url)
|
30
|
+
order_purchased(details: params.merge(verify_params), provider: 'moneris', card: params[:card], redirect_url: purchased_redirect_url)
|
31
31
|
else
|
32
|
-
order_declined(params.merge(verify_params), declined_redirect_url)
|
32
|
+
order_declined(details: params.merge(verify_params), provider: 'moneris', card: params[:card], redirect_url: declined_redirect_url)
|
33
33
|
end
|
34
34
|
else
|
35
|
-
order_declined(params, declined_redirect_url)
|
35
|
+
order_declined(details: params, provider: 'moneris', card: params[:card], redirect_url: declined_redirect_url)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def parse_moneris_response(text)
|
42
|
-
text.split("<br>").inject(Hash.new()) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last ; h } rescue {:
|
42
|
+
text.split("<br>").inject(Hash.new()) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last ; h } rescue {response: text}
|
43
43
|
end
|
44
44
|
|
45
45
|
def send_moneris_verify_request(verify_key)
|
@@ -93,4 +93,4 @@ end
|
|
93
93
|
# Sent to your server as a POST
|
94
94
|
# Response URL: http://ourwebsite.com/orders/moneris_postback
|
95
95
|
|
96
|
-
# Displayed as key/value pairs on our server
|
96
|
+
# Displayed as key/value pairs on our server
|
@@ -5,20 +5,22 @@ module Effective
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
skip_before_filter :verify_authenticity_token, :only => [:paypal_postback]
|
8
|
+
|
9
|
+
if defined?(CanCan)
|
10
|
+
skip_authorization_check only: [:paypal_postback]
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def paypal_postback
|
11
15
|
@order ||= Effective::Order.where(id: (params[:invoice].to_i rescue 0)).first
|
12
16
|
|
13
|
-
EffectiveOrders.authorized?(self, :update, @order)
|
14
|
-
|
15
17
|
if @order.present?
|
16
18
|
if @order.purchased?
|
17
|
-
order_purchased(params)
|
19
|
+
order_purchased(details: params, provider: 'paypal', card: params[:payment_type])
|
18
20
|
elsif (params[:payment_status] == 'Completed' && params[:custom] == EffectiveOrders.paypal[:secret])
|
19
|
-
order_purchased(params)
|
21
|
+
order_purchased(details: params, provider: 'paypal', card: params[:payment_type])
|
20
22
|
else
|
21
|
-
order_declined(params)
|
23
|
+
order_declined(details: params, provider: 'paypal', card: params[:payment_type])
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Effective
|
2
|
+
module Providers
|
3
|
+
module Pretend
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def pretend_purchase
|
7
|
+
@order ||= Order.find(params[:id])
|
8
|
+
|
9
|
+
EffectiveOrders.authorized?(self, :update, @order)
|
10
|
+
|
11
|
+
order_purchased(
|
12
|
+
details: 'for pretend',
|
13
|
+
provider: 'pretend',
|
14
|
+
card: 'none',
|
15
|
+
redirect_url: params[:purchased_redirect_url],
|
16
|
+
declined_redirect_url: params[:declined_redirect_url]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -3,21 +3,23 @@ module Effective
|
|
3
3
|
module Stripe
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
included do
|
7
|
-
end
|
8
|
-
|
9
6
|
def stripe_charge
|
10
7
|
@order ||= Effective::Order.find(stripe_charge_params[:effective_order_id])
|
11
|
-
@stripe_charge = Effective::StripeCharge.new(stripe_charge_params)
|
8
|
+
@stripe_charge = Effective::Providers::StripeCharge.new(stripe_charge_params)
|
12
9
|
@stripe_charge.order = @order
|
13
10
|
|
14
11
|
EffectiveOrders.authorized?(self, :update, @order)
|
15
12
|
|
16
13
|
if @stripe_charge.valid? && (response = process_stripe_charge(@stripe_charge)) != false
|
17
|
-
order_purchased(
|
14
|
+
order_purchased(
|
15
|
+
details: response,
|
16
|
+
provider: (EffectiveOrders.stripe_connect_enabled ? 'stripe_connect' : 'stripe'),
|
17
|
+
card: (response['charge']['card']['brand'] rescue nil)
|
18
|
+
)
|
18
19
|
else
|
19
|
-
|
20
|
-
|
20
|
+
@page_title = 'Checkout'
|
21
|
+
flash.now[:danger] = @stripe_charge.errors.full_messages.to_sentence
|
22
|
+
render :checkout_step2
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -44,16 +46,16 @@ module Effective
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def charge_with_stripe(charge, buyer)
|
47
|
-
results = {:
|
49
|
+
results = {subscriptions: {}, charge: nil}
|
48
50
|
|
49
51
|
# Process subscriptions.
|
50
52
|
charge.subscriptions.each do |subscription|
|
51
53
|
next if subscription.stripe_plan_id.blank?
|
52
54
|
|
53
55
|
stripe_subscription = if subscription.stripe_coupon_id.present?
|
54
|
-
buyer.stripe_customer.subscriptions.create({:
|
56
|
+
buyer.stripe_customer.subscriptions.create({plan: subscription.stripe_plan_id, coupon: subscription.stripe_coupon_id})
|
55
57
|
else
|
56
|
-
buyer.stripe_customer.subscriptions.create({:
|
58
|
+
buyer.stripe_customer.subscriptions.create({plan: subscription.stripe_plan.id})
|
57
59
|
end
|
58
60
|
|
59
61
|
subscription.stripe_subscription_id = stripe_subscription.id
|
@@ -63,15 +65,15 @@ module Effective
|
|
63
65
|
end
|
64
66
|
|
65
67
|
# Process regular order_items.
|
66
|
-
amount =
|
68
|
+
amount = charge.order_items.map { |oi| oi.total }.sum # A positive integer in cents representing how much to charge the card. The minimum amount is 50 cents.
|
67
69
|
description = "Charge for Order ##{charge.order.to_param}"
|
68
70
|
|
69
71
|
if amount > 0
|
70
72
|
results[:charge] = JSON.parse(::Stripe::Charge.create(
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
73
|
+
amount: amount,
|
74
|
+
currency: EffectiveOrders.stripe[:currency],
|
75
|
+
customer: buyer.stripe_customer.id,
|
76
|
+
description: description
|
75
77
|
).to_json)
|
76
78
|
end
|
77
79
|
|
@@ -85,22 +87,22 @@ module Effective
|
|
85
87
|
|
86
88
|
# We do all these Tokens first, so if one throws an exception no charges are made
|
87
89
|
items.each do |seller, _|
|
88
|
-
seller.token = ::Stripe::Token.create({:
|
90
|
+
seller.token = ::Stripe::Token.create({customer: buyer.stripe_customer.id}, seller.stripe_connect_access_token)
|
89
91
|
end
|
90
92
|
|
91
93
|
# Make one charge per seller, for all his order_items
|
92
94
|
items.each do |seller, order_items|
|
93
|
-
amount = order_items.sum
|
95
|
+
amount = order_items.map { |oi| oi.total }.sum
|
94
96
|
description = "Charge for Order ##{charge.order.to_param} with OrderItems ##{order_items.map(&:id).join(', #')}"
|
95
97
|
application_fee = order_items.sum(&:stripe_connect_application_fee)
|
96
98
|
|
97
99
|
results[seller.id] = JSON.parse(::Stripe::Charge.create(
|
98
100
|
{
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
101
|
+
amount: amount,
|
102
|
+
currency: EffectiveOrders.stripe[:currency],
|
103
|
+
card: seller.token.id,
|
104
|
+
description: description,
|
105
|
+
application_fee: application_fee
|
104
106
|
},
|
105
107
|
seller.stripe_connect_access_token
|
106
108
|
).to_json)
|
@@ -112,9 +114,9 @@ module Effective
|
|
112
114
|
# StrongParameters
|
113
115
|
def stripe_charge_params
|
114
116
|
begin
|
115
|
-
params.require(:
|
117
|
+
params.require(:effective_providers_stripe_charge).permit(:token, :effective_order_id)
|
116
118
|
rescue => e
|
117
|
-
params[:
|
119
|
+
params[:effective_providers_stripe_charge]
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
@@ -68,7 +68,7 @@ module Effective
|
|
68
68
|
# Now we have to purchase it
|
69
69
|
@order = Effective::Order.new(subscription)
|
70
70
|
@order.user = @customer.user
|
71
|
-
@order.purchase!("
|
71
|
+
@order.purchase!(details: "Webhook #{event.id}", provider: 'stripe')
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -4,12 +4,12 @@ module EffectiveCartsHelper
|
|
4
4
|
user = for_user || (current_user rescue nil) # rescue protects me against Devise not being installed
|
5
5
|
|
6
6
|
if user.present?
|
7
|
-
Effective::Cart.where(:
|
7
|
+
Effective::Cart.where(user_id: user.id).first_or_create.tap do |user_cart|
|
8
8
|
if session[:cart].present?
|
9
|
-
session_cart = Effective::Cart.where('user_id IS NULL').where(:
|
9
|
+
session_cart = Effective::Cart.where('user_id IS NULL').where(id: session[:cart]).first
|
10
10
|
|
11
11
|
if session_cart.present?
|
12
|
-
session_cart.cart_items.update_all(:
|
12
|
+
session_cart.cart_items.update_all(cart_id: user_cart.id)
|
13
13
|
session_cart.destroy
|
14
14
|
user_cart.reload
|
15
15
|
end
|
@@ -18,7 +18,7 @@ module EffectiveCartsHelper
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
elsif session[:cart].present?
|
21
|
-
Effective::Cart.where('user_id IS NULL').where(:
|
21
|
+
Effective::Cart.where('user_id IS NULL').where(id: session[:cart]).first_or_create
|
22
22
|
else
|
23
23
|
cart = Effective::Cart.create!
|
24
24
|
session[:cart] = cart.id
|
@@ -28,73 +28,103 @@ module EffectiveCartsHelper
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def link_to_current_cart(opts = {})
|
31
|
-
options = {
|
31
|
+
options = {
|
32
|
+
label: 'My Cart',
|
33
|
+
id: 'current_cart',
|
34
|
+
rel: :nofollow,
|
35
|
+
class: 'btn btn-default'
|
36
|
+
}.merge(opts)
|
37
|
+
|
38
|
+
label = options.delete(:label)
|
39
|
+
options[:class] = ((options[:class] || '') + ' btn-current-cart')
|
32
40
|
|
33
|
-
label = options.delete(:label) || 'Cart'
|
34
41
|
link_to (current_cart.size == 0 ? label : "#{label} (#{current_cart.size})"), effective_orders.cart_path, options
|
35
42
|
end
|
36
43
|
|
37
44
|
def link_to_add_to_cart(purchasable, opts = {})
|
38
|
-
raise ArgumentError.new('expecting an acts_as_purchasable object') unless purchasable.
|
45
|
+
raise ArgumentError.new('expecting an acts_as_purchasable object') unless purchasable.kind_of?(ActsAsPurchasable)
|
39
46
|
|
40
|
-
options = {
|
47
|
+
options = {
|
48
|
+
label: 'Add to Cart',
|
49
|
+
class: 'btn btn-primary',
|
50
|
+
rel: :nofollow,
|
51
|
+
data: {
|
52
|
+
disable_with: 'Adding...'
|
53
|
+
}
|
54
|
+
}.merge(opts)
|
55
|
+
|
56
|
+
label = options.delete(:label)
|
41
57
|
options[:class] = ((options[:class] || '') + ' btn-add-to-cart')
|
42
58
|
|
43
|
-
link_to
|
59
|
+
link_to label, effective_orders.add_to_cart_path(purchasable_type: purchasable.class.name, purchasable_id: purchasable.id.to_i), options
|
44
60
|
end
|
45
61
|
|
46
62
|
def link_to_remove_from_cart(cart_item, opts = {})
|
47
63
|
raise ArgumentError.new('expecting an Effective::CartItem object') unless cart_item.kind_of?(Effective::CartItem)
|
48
64
|
|
49
65
|
options = {
|
50
|
-
:
|
51
|
-
:
|
52
|
-
|
53
|
-
|
66
|
+
label: 'Remove',
|
67
|
+
class: 'btn btn-primary',
|
68
|
+
rel: :nofollow,
|
69
|
+
data: {
|
70
|
+
confirm: 'Are you sure? This cannot be undone!',
|
71
|
+
disable_with: 'Removing...'
|
54
72
|
},
|
55
|
-
:
|
73
|
+
method: :delete
|
56
74
|
}.merge(opts)
|
57
75
|
|
76
|
+
label = options.delete(:label)
|
58
77
|
options[:class] = ((options[:class] || '') + ' btn-remove-from-cart')
|
59
78
|
|
60
|
-
link_to
|
79
|
+
link_to(label, effective_orders.remove_from_cart_path(cart_item), options)
|
61
80
|
end
|
62
81
|
|
63
82
|
def link_to_empty_cart(opts = {})
|
64
83
|
options = {
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
|
69
|
-
:
|
84
|
+
label: 'Empty Cart',
|
85
|
+
class: 'btn btn-danger',
|
86
|
+
rel: :nofollow,
|
87
|
+
data: {
|
88
|
+
confirm: 'This will clear your entire cart. Are you sure?',
|
89
|
+
disable_with: 'Emptying...'
|
70
90
|
},
|
71
|
-
:
|
91
|
+
method: :delete
|
72
92
|
}.merge(opts)
|
73
93
|
|
74
|
-
|
94
|
+
label = options.delete(:label)
|
95
|
+
options[:class] = ((options[:class] || '') + ' btn-empty-cart')
|
75
96
|
|
76
|
-
link_to
|
97
|
+
link_to(label, effective_orders.cart_path, options)
|
77
98
|
end
|
78
99
|
|
79
100
|
def link_to_checkout(opts = {})
|
80
101
|
options = {
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
102
|
+
label: 'Checkout',
|
103
|
+
class: 'btn btn-primary',
|
104
|
+
rel: :nofollow,
|
105
|
+
data: {
|
106
|
+
disable_with: 'Continuing...'
|
107
|
+
},
|
84
108
|
}.merge(opts)
|
85
109
|
|
110
|
+
order = options.delete(:order)
|
111
|
+
label = options.delete(:label)
|
86
112
|
options[:class] = ((options[:class] || '') + ' btn-checkout')
|
87
113
|
|
88
|
-
|
114
|
+
if order.present?
|
115
|
+
link_to(label, effective_orders.edit_order_path(order), options)
|
116
|
+
else
|
117
|
+
link_to(label, effective_orders.new_order_path, options)
|
118
|
+
end
|
89
119
|
end
|
90
120
|
|
91
121
|
def render_cart(cart = nil)
|
92
122
|
cart ||= current_cart
|
93
|
-
render(:
|
123
|
+
render(partial: 'effective/carts/cart', locals: {cart: cart})
|
94
124
|
end
|
95
125
|
|
96
126
|
def render_purchasables(*purchasables)
|
97
|
-
render(:
|
127
|
+
render(partial: 'effective/orders/order_items', locals: {order: Effective::Order.new(purchasables)})
|
98
128
|
end
|
99
129
|
|
100
130
|
end
|