Class: Spree::Billing::ProductsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/billing/products_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#collection_url, #current_vendor, #default_url_options, #edit_object_url, #handle_unauthorized_vendor, #page, #per_page, #required_vendor_user!, #set_locale, #switch_vendor, #vendors

Methods included from SpreeCmCommissioner::Billing::RoleAuthorization

#auth_action, #auth_entry, #auth_user, #authorize!, #authorize?, #authorize_admin, #authorize_role!, #redirect_unauthorized_access

Instance Method Details

#collectionObject



10
11
12
13
14
15
# File 'app/controllers/spree/billing/products_controller.rb', line 10

def collection
  return @collection if defined?(@collection)

  @search = scope.ransack(params[:q])
  @collection = @search.result.page(page).per(per_page)
end

#find_resourceObject

overrided



25
26
27
# File 'app/controllers/spree/billing/products_controller.rb', line 25

def find_resource
  scope.find_by(slug: params[:id])
end

#load_dataObject



17
18
19
20
21
22
# File 'app/controllers/spree/billing/products_controller.rb', line 17

def load_data
  @option_types = OptionType.order(:name)
  @tax_categories = TaxCategory.order(:name)
  @shipping_categories = ShippingCategory.order(:name)
  @businesses = Spree::Taxonomy.businesses.taxons.where('depth > ? ', 1).order('parent_id ASC').uniq
end

#location_after_saveObject



29
30
31
# File 'app/controllers/spree/billing/products_controller.rb', line 29

def location_after_save
  edit_billing_product_url(@product)
end

#model_classObject



47
48
49
# File 'app/controllers/spree/billing/products_controller.rb', line 47

def model_class
  Spree::Product
end

#object_nameObject



51
52
53
# File 'app/controllers/spree/billing/products_controller.rb', line 51

def object_name
  'product'
end

#scopeObject



6
7
8
# File 'app/controllers/spree/billing/products_controller.rb', line 6

def scope
  current_vendor.products.where(subscribable: true)
end

#stockObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/spree/billing/products_controller.rb', line 37

def stock
  @variants = @product.variants.includes(*variant_stock_includes)
  @variants = [@product.master] if @variants.empty?
  @stock_locations = StockLocation.accessible_by(current_ability)
  return unless @stock_locations.empty?

  flash[:error] = Spree.t(:stock_management_requires_a_stock_location)
  redirect_to spree.admin_stock_locations_path
end

#variant_stock_includesObject



33
34
35
# File 'app/controllers/spree/billing/products_controller.rb', line 33

def variant_stock_includes
  [:images, { stock_items: :stock_location, option_values: :option_type }]
end