Class: ViewItem

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

Overview

== Schema Information

Table name: view_items
Database name: primary

id :integer primary key
all_pl_paths_ids :ltree is an Array
all_pl_paths_slugs :ltree is an Array
amazon_asin :string(10)
available_online :boolean
box1_volume_cubic_ft :decimal(, )
box2_shipping_height :decimal(6, 2)
box2_shipping_length :decimal(6, 2)
box2_shipping_weight :decimal(8, 4)
box2_shipping_width :decimal(6, 2)
box2_volume_cubic_ft :decimal(, )
box3_shipping_height :decimal(6, 2)
box3_shipping_length :decimal(6, 2)
box3_shipping_weight :decimal(8, 4)
box3_shipping_width :decimal(6, 2)
box3_volume_cubic_ft :decimal(, )
condition :string(20)
description_length :integer
detailed_description_html :text
gtin13 :text
is_discontinued :boolean
is_kit :boolean
name :string(255)
oversize :boolean
packageable :boolean
pc_path_ids :ltree
pc_path_slugs :ltree
primary_pl_path_ids :ltree
primary_pl_path_slugs :ltree
primary_product_line_lineage :string(255)
product_category_lineage :text
rendered_product_specifications :jsonb
requested_counter :integer
review_product_packaging_flag :boolean
review_product_weight_flag :boolean
seo_description :text
seo_keywords :string
seo_title :string
shipping_height :decimal(6, 2)
shipping_length :decimal(6, 2)
shipping_weight :decimal(8, 4)
shipping_width :decimal(6, 2)
sku :string
sku_aliases :string is an Array
supplier_sku :text
total_available_stock :decimal(, )
total_available_stock_can :decimal(, )
total_available_stock_usa :decimal(, )
upc :string(255)
created_at :datetime
updated_at :datetime
literature_id :integer
primary_product_line_id :integer
product_category_id :integer

Belongs to collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::SearchableView

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

Methods included from Models::ItemScopable

by_product_category_id, by_product_category_id_direct, by_product_category_path, by_product_category_path_exact, by_product_category_url, by_product_category_url_exact, by_product_line_id, by_product_line_path, by_product_line_path_full, by_product_line_url, by_product_line_url_full, not_by_product_category_id, not_by_product_line_id

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.available_to_publicActiveRecord::Relation<ViewItem>

A relation of ViewItems that are available to public. Active Record Scope

Returns:

See Also:



92
# File 'app/models/view_item.rb', line 92

scope :available_to_public,        ->(include = '1') { include.to_s.to_b ? joins(:item).merge(Item.available_to_public) : all }

.in_catalogActiveRecord::Relation<ViewItem>

A relation of ViewItems that are in catalog. Active Record Scope

Returns:

See Also:



82
83
84
85
86
87
88
89
90
# File 'app/models/view_item.rb', line 82

scope :in_catalog, ->(catalog_id) {
  where("EXISTS(select 1 from catalog_items ci
                    inner join store_items si on si.id = ci.store_item_id
                    where si.item_id = #{table_name}.id
                      and ci.catalog_id IN (?)
                      and ci.state IN (?))",
        catalog_id,
        CatalogItem::EDI_FEED_STATUSES)
}

.in_catalog_and_activeActiveRecord::Relation<ViewItem>

A relation of ViewItems that are in catalog and active. Active Record Scope

Returns:

See Also:



91
# File 'app/models/view_item.rb', line 91

scope :in_catalog_and_active,      ->(*catalog_ids) { joins(:item).merge(Item.active_in_catalog_ids(catalog_ids)) }

.not_in_catalogActiveRecord::Relation<ViewItem>

A relation of ViewItems that are not in catalog. Active Record Scope

Returns:

See Also:



73
74
75
76
77
78
79
80
81
# File 'app/models/view_item.rb', line 73

scope :not_in_catalog,             ->(catalog_id) {
  where.not("EXISTS(select 1 from catalog_items ci
                    inner join store_items si on si.id = ci.store_item_id
                    where si.item_id = #{table_name}.id
                      and ci.catalog_id IN (?)
                      and ci.state IN (?))",
            catalog_id,
            CatalogItem::EDI_FEED_STATUSES)
}

.ransackable_scopes(_auth_object = nil) ⇒ Object



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

def self.ransackable_scopes(_auth_object = nil)
  super + %i[keywords_search available_to_public in_catalog in_catalog_and_active not_in_catalog
             with_product_specification by_product_category_id by_product_line_id]
end

.with_catalog_itemActiveRecord::Relation<ViewItem>

A relation of ViewItems that are with catalog item. Active Record Scope

Returns:

See Also:



72
# File 'app/models/view_item.rb', line 72

scope :with_catalog_item,          -> { joins(store_items: :catalog_items) }

.with_product_specificationActiveRecord::Relation<ViewItem>

A relation of ViewItems that are with product specification. Active Record Scope

Returns:

See Also:



93
# File 'app/models/view_item.rb', line 93

scope :with_product_specification, ->(token, value) { where('view_items.rendered_product_specifications @> ?', { token => { raw: TypeCoercer.coerce(value) } }.to_json) }

Instance Method Details

#itemItem

Returns:

See Also:



66
# File 'app/models/view_item.rb', line 66

belongs_to :item, foreign_key: :id, optional: true

#primary_product_lineProductLine



67
# File 'app/models/view_item.rb', line 67

belongs_to :primary_product_line, class_name: 'ProductLine', optional: true

#product_categoryProductCategory



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

belongs_to :product_category, optional: true

#store_itemsActiveRecord::Relation<StoreItem>

Returns:

See Also:



69
# File 'app/models/view_item.rb', line 69

has_many :store_items, foreign_key: :item_id

#thumbnail_urlObject



103
104
105
# File 'app/models/view_item.rb', line 103

def thumbnail_url
  item.thumbnail_url if item
end