Class: Spree::Billing::CustomersController
- Inherits:
-
BaseController
- Object
- Admin::ResourceController
- BaseController
- Spree::Billing::CustomersController
show all
- Defined in:
- app/controllers/spree/billing/customers_controller.rb
Instance Method Summary
collapse
#current_vendor, #default_url_options, #edit_object_url, #handle_unauthorized_vendor, #page, #per_page, #required_vendor_user!, #set_locale, #switch_vendor, #vendors
#auth_action, #auth_entry, #auth_user, #authorize!, #authorize?, #authorize_admin, #authorize_role!, #redirect_unauthorized_access
Instance Method Details
POST /billing/customers/:customer_id/apply_promotion billing_customer_apply_promotion_path
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 49
def apply_promotion
result = SpreeCmCommissioner::CustomerPromotionCreator.call(
customer_id: params[:customer_id],
reason: params[:reason],
discount_amount: params[:discount_amount],
store: current_store
)
if result.success?
flash[:success] = I18n.t('spree.billing.customers.apply_promotion.success')
else
flash[:error] = I18n.t('spree.billing.customers.apply_promotion.fails', error: result.message)
end
redirect_back(fallback_location: billing_customer_orders_path(params[:customer_id]))
end
|
#collection ⇒ Object
16
17
18
19
20
21
22
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 16
def collection
return [] if current_vendor.blank?
return @collection if defined?(@collection)
@search = scope.ransack(params[:q])
@collection = @search.result.includes(:subscriptions, :taxons).page(page).per(per_page)
end
|
#collection_url(options = {}) ⇒ Object
90
91
92
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 90
def collection_url(options = {})
billing_customers_url(options)
end
|
delete /billing/customers/:customer_id/delete_promotion/:id billing_customer_delete_promotion_url
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 68
def delete_promotion
customer = model_class.find(params[:customer_id])
promotion = Spree::Promotion.find_by(code: customer.number)
if promotion.destroy
flash[:success] = I18n.t('spree.billing.customers.delete_promotion.success')
else
flash[:error] = I18n.t('spree.billing.customers.delete_promotion.fails', error: result.message)
end
redirect_back(fallback_location: billing_customer_orders_path(params[:customer_id]))
end
|
#load_bussinesses ⇒ Object
28
29
30
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 28
def load_bussinesses
@businesses = Spree::Taxonomy.businesses.taxons.where('depth > ? ', 1).order('parent_id ASC').uniq
end
|
#load_customer ⇒ Object
24
25
26
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 24
def load_customer
@customer = @object
end
|
#location_after_save ⇒ Object
94
95
96
97
98
99
100
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 94
def location_after_save
if permitted_resource_params.key?(:bill_address_attributes) && permitted_resource_params.key?(:ship_address_attributes)
billing_customer_addresses_url(@customer)
else
edit_billing_customer_url(@customer)
end
end
|
#object_name ⇒ Object
85
86
87
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 85
def object_name
'spree_cm_commissioner_customer'
end
|
#re_create_order ⇒ Object
POST /billing/customers/:customer_id/re_create_order billing_customer_re_create_order_path
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 34
def re_create_order
today = Time.zone.today
customer = model_class.find_by(id: params[:customer_id])
result = SpreeCmCommissioner::SubscriptionsOrderCreator.call(customer: customer, today: today)
if result.failure?
flash[:error] = I18n.t('spree.billing.customers.re_create_order.fails', error: result.error)
else
flash[:success] = I18n.t('spree.billing.customers.re_create_order.success', success: result.success)
end
redirect_back(fallback_location: billing_customer_orders_path(customer))
end
|
#scope ⇒ Object
8
9
10
11
12
13
14
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 8
def scope
if spree_current_user.has_spree_role?('admin')
current_vendor.customers
else
current_vendor.customers.where(place_id: spree_current_user.place_ids)
end
end
|
#set_vendor ⇒ Object
102
103
104
|
# File 'app/controllers/spree/billing/customers_controller.rb', line 102
def set_vendor
permitted_resource_params[:vendor] = current_vendor
end
|