Class: Dscf::Marketplace::Product

Inherits:
ApplicationRecord show all
Defined in:
app/models/dscf/marketplace/product.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



35
36
37
# File 'app/models/dscf/marketplace/product.rb', line 35

def self.ransackable_associations(_auth_object = nil)
  %w[category unit supplier_products listings order_items rfq_items quotation_items]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object

Ransack configuration for secure filtering



31
32
33
# File 'app/models/dscf/marketplace/product.rb', line 31

def self.ransackable_attributes(_auth_object = nil)
  %w[id sku name description category_id unit_id base_price base_quantity business_only created_at updated_at]
end

Instance Method Details

#category_pathObject



48
49
50
51
# File 'app/models/dscf/marketplace/product.rb', line 48

def category_path
  return nil unless category
  category.ancestry_path
end

#convertible_to_unitsObject



53
54
55
56
# File 'app/models/dscf/marketplace/product.rb', line 53

def convertible_to_units
  return [] unless unit
  unit.convertible_units
end

#display_nameObject



39
40
41
# File 'app/models/dscf/marketplace/product.rb', line 39

def display_name
  "#{name} (#{sku})"
end

#images_urlsObject



62
63
64
65
# File 'app/models/dscf/marketplace/product.rb', line 62

def images_urls
  return [] unless images.attached?
  images.map { |image| attachment_url_for(image) }
end

#price_per_unitObject



43
44
45
46
# File 'app/models/dscf/marketplace/product.rb', line 43

def price_per_unit
  return nil unless base_price && base_quantity && base_quantity > 0
  base_price / base_quantity
end

#thumbnail_urlObject



58
59
60
# File 'app/models/dscf/marketplace/product.rb', line 58

def thumbnail_url
  attachment_url_for(thumbnail)
end