Class: ViewItemCatalog

Inherits:
ApplicationViewRecord show all
Includes:
Models::SearchableView, PgSearch::Model
Defined in:
app/models/view_item_catalog.rb

Overview

== Schema Information

Table name: view_item_catalogs
Database name: primary

id :integer primary key
all_pl_paths_ids :ltree is an Array
all_pl_paths_slugs :ltree is an Array
catalog_item_amount :decimal(8, 2)
catalog_item_is_discontinued :boolean
catalog_item_max_discount :integer
catalog_item_state :string(30)
catalog_item_stock_reserved :integer
inherited_item_product_category_ids :integer is an Array
inherited_item_product_line_ids :integer is an Array
item_condition :enum
item_dropship :boolean
item_is_available_to_public :boolean
item_is_discontinued :boolean
item_name :string(255)
item_oversize :boolean
item_qty_out_of_stock :integer
item_require_reservation :boolean
item_shipping_class :enum
item_sku :string
item_unlimited_inventory :boolean
item_warn_on_stock :integer
pc_path_ids :ltree
pc_path_slugs :ltree
primary_pl_path_ids :ltree
primary_pl_path_slugs :ltree
product_category_lineage_expanded :text
product_category_name :string(255)
product_category_priority :integer
product_line_ids :integer is an Array
restricted_for_sales :boolean
store_item_qty_available :integer
store_item_qty_committed :integer
store_item_qty_on_hand :integer
store_item_unit_cogs :decimal(, )
catalog_id :integer
catalog_item_id :integer
item_id :integer
item_product_category_id :integer
literature_id :integer
store_item_id :integer

Constant Summary

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Class Method Summary collapse

Methods included from Models::SearchableView

#crm_link, #crm_link_subtitle, #has_columns?, #readonly?

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.activeActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are active. Active Record Scope

Returns:

See Also:



68
# File 'app/models/view_item_catalog.rb', line 68

scope :active, -> { where.not(item_is_discontinued: true).where(catalog_item_state: %w[active active_hidden]) }

.belongs_to_product_category_idActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are belongs to product category id. Active Record Scope

Returns:

See Also:



79
80
81
82
83
84
# File 'app/models/view_item_catalog.rb', line 79

scope :belongs_to_product_category_id, ->(pcid) {
  ids = [pcid].flatten.compact.uniq
  return none if ids.empty?

  where.ltree_contains(:pc_path_ids, ids, array: false)
}

.belongs_to_product_line_idActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are belongs to product line id. Active Record Scope

Returns:

See Also:



71
72
73
74
75
76
# File 'app/models/view_item_catalog.rb', line 71

scope :belongs_to_product_line_id, ->(plid) {
  ids = [plid].flatten.compact.uniq
  return none if ids.empty?

  where.ltree_contains(:all_pl_paths_ids, ids)
}

.excluding_out_of_stock_refurbActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are excluding out of stock refurb. Active Record Scope

Returns:

See Also:



87
88
89
# File 'app/models/view_item_catalog.rb', line 87

scope :excluding_out_of_stock_refurb, -> {
  where("view_item_catalogs.item_condition = 'new' OR (view_item_catalogs.item_condition = 'refurbished' AND view_item_catalogs.store_item_qty_available > 0)")
}

.ransackable_scopes(_auth_object = nil) ⇒ Object

Expose ltree-powered scopes to Ransack for efficient hierarchy filtering



99
100
101
# File 'app/models/view_item_catalog.rb', line 99

def self.ransackable_scopes(_auth_object = nil)
  %i[belongs_to_product_line_id belongs_to_product_category_id]
end

.unrestrictedActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are unrestricted. Active Record Scope

Returns:

See Also:



86
# File 'app/models/view_item_catalog.rb', line 86

scope :unrestricted, -> { where.not(restricted_for_sales: true) }

.with_skusActiveRecord::Relation<ViewItemCatalog>

A relation of ViewItemCatalogs that are with skus. Active Record Scope

Returns:

See Also:



90
# File 'app/models/view_item_catalog.rb', line 90

scope :with_skus, ->(skus) { where(item_sku: skus) }

Instance Method Details

#catalog_itemCatalogItem



55
# File 'app/models/view_item_catalog.rb', line 55

belongs_to :catalog_item, optional: true

#itemItem

Returns:

See Also:



53
# File 'app/models/view_item_catalog.rb', line 53

belongs_to :item, optional: true

#store_itemStoreItem

Returns:

See Also:



54
# File 'app/models/view_item_catalog.rb', line 54

belongs_to :store_item, optional: true