Class: ViewAmazonCatalogItem

Inherits:
ApplicationViewRecord show all
Defined in:
app/models/view_amazon_catalog_item.rb

Overview

== Schema Information

Table name: view_amazon_catalog_items
Database name: primary

id :integer primary key
amazon_asin :string(10)
amazon_info_datetime :datetime
amazon_min_price_with_tax :decimal(, )
amazon_price_with_tax :decimal(, )
amazon_product_url :text
amount :decimal(8, 2)
amz_last_buy_box_winner_change :datetime
amz_min_seller_price_override :decimal(8, 2)
catalog_name :string(255)
currency :string(255)
currency_symbol :string(255)
effective_price :decimal(8, 2)
effective_price_with_vat :decimal(, )
goods_vat_rate :decimal(6, 4)
is_amz_buy_box_winner :boolean
is_amz_featured_merchant :boolean
item_name :text
item_suppressed_status :string
item_suppressed_status_message :string
marketplace_identifier :string(20)
old_amount :decimal(10, 2)
price_updated_at :datetime
price_with_vat :decimal(, )
retail_price :decimal(8, 2)
retailer_information :jsonb
sale_price :decimal(8, 2)
sku :string
state :string(30)
url :string
catalog_id :integer
catalog_item_id :integer
item_id :integer
store_item_id :integer

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.activeActiveRecord::Relation<ViewAmazonCatalogItem>

A relation of ViewAmazonCatalogItems that are active. Active Record Scope

Returns:

See Also:



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

scope :active, -> { where(state: 'active') }

.for_catalogActiveRecord::Relation<ViewAmazonCatalogItem>

A relation of ViewAmazonCatalogItems that are for catalog. Active Record Scope

Returns:

See Also:



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

scope :for_catalog, ->(catalog_id) { where(catalog_id: catalog_id) }

.ransackable_associations(_auth_object = nil) ⇒ Array<String>

Parameters:

  • _auth_object (Object, nil) (defaults to: nil)

    unused Ransack auth object

Returns:

  • (Array<String>)


73
74
75
# File 'app/models/view_amazon_catalog_item.rb', line 73

def self.ransackable_associations(_auth_object = nil)
  %w[amazon_catalog_item_flags]
end

.ransackable_attributes(_auth_object = nil) ⇒ Array<String>

Ransack configuration - allow searching on flattened columns

Parameters:

  • _auth_object (Object, nil) (defaults to: nil)

    unused Ransack auth object

Returns:

  • (Array<String>)


61
62
63
64
65
66
67
68
69
# File 'app/models/view_amazon_catalog_item.rb', line 61

def self.ransackable_attributes(_auth_object = nil)
  %w[
    id catalog_id store_item_id item_id amount sale_price state
    sku item_name amazon_asin catalog_name
    is_amz_buy_box_winner is_amz_featured_merchant
    reprice_rule reprice_target_price
    price_updated_at amazon_info_datetime
  ]
end

.with_stateActiveRecord::Relation<ViewAmazonCatalogItem>

A relation of ViewAmazonCatalogItems that are with state. Active Record Scope

Returns:

See Also:



56
# File 'app/models/view_amazon_catalog_item.rb', line 56

scope :with_state, ->(states) { where(state: states) }

Instance Method Details

#amazon_catalog_item_flagsActiveRecord::Relation<AmazonCatalogItemFlag>

Returns:



51
# File 'app/models/view_amazon_catalog_item.rb', line 51

has_many :amazon_catalog_item_flags, foreign_key: :catalog_item_id, primary_key: :catalog_item_id

#amazon_minimum_seller_allowed_price_with_taxObject

Alias for helpers expecting this method



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

def amazon_minimum_seller_allowed_price_with_tax
  amazon_min_price_with_tax
end

#catalogCatalog?

Returns:



49
# File 'app/models/view_amazon_catalog_item.rb', line 49

belongs_to :catalog, optional: true

#catalog_itemCatalogItem

Associations for preloading additional data not in the view



47
# File 'app/models/view_amazon_catalog_item.rb', line 47

belongs_to :catalog_item, optional: true

#itemObject

Compatibility aliases for helpers that expect nested structure
These delegate to flattened columns from the view



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

def item
  # Simple struct for helpers expecting catalog_item.item.sku
  @item ||= Struct.new(:id, :sku, :name, :amazon_asin).new(
    item_id, sku, item_name, amazon_asin
  )
end

#store_itemStruct

Returns:

  • (Struct)


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

def store_item
  # Simple struct for helpers expecting catalog_item.store_item.item_id
  @store_item ||= Struct.new(:id, :item_id).new(store_item_id, item_id)
end

#tax_rateObject

Tax rate from view (already computed in SQL)



93
94
95
# File 'app/models/view_amazon_catalog_item.rb', line 93

def tax_rate
  goods_vat_rate
end