Class: Dscf::Marketplace::Product

Inherits:
ApplicationRecord show all
Includes:
AttachmentUrls
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



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

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



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

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

Instance Method Details

#category_pathObject



51
52
53
54
# File 'app/models/dscf/marketplace/product.rb', line 51

def category_path
  return nil unless category
  category.ancestry_path
end

#convertible_to_unitsObject



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

def convertible_to_units
  return [] unless unit
  unit.convertible_units
end

#display_nameObject



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

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

#images_urlsObject



65
66
67
68
# File 'app/models/dscf/marketplace/product.rb', line 65

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

#price_per_unitObject



46
47
48
49
# File 'app/models/dscf/marketplace/product.rb', line 46

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

#thumbnail_urlObject



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

def thumbnail_url
  attachment_url_for(thumbnail)
end