Class: AmazonCatalogItemFlag
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AmazonCatalogItemFlag
- Defined in:
- app/models/amazon_catalog_item_flag.rb
Overview
== Schema Information
Table name: amazon_catalog_item_flags
Database name: primary
id :bigint not null, primary key
competitive_price :decimal(10, 2)
flag_type :string not null
issues :text
our_price_at_flagging :decimal(10, 2)
resolved_at :datetime
created_at :datetime not null
updated_at :datetime not null
catalog_item_id :bigint not null
competitor_seller_id :string
resolved_by_id :integer
Indexes
index_amazon_catalog_item_flags_on_catalog_item_id (catalog_item_id)
index_amazon_catalog_item_flags_on_flag_type (flag_type)
index_amazon_catalog_item_flags_on_resolved_at (resolved_at)
Foreign Keys
fk_rails_... (catalog_item_id => catalog_items.id)
Constant Summary collapse
- FLAG_TYPES =
{ has_issues: 'has_issues', cannot_automatically_win_buy_box: 'cannot_automatically_win_buy_box', no_buyable_offers: 'no_buyable_offers', out_of_stock: 'out_of_stock', external_competitor: 'external_competitor', reprice_blocked_by_external: 'reprice_blocked_by_external' }.freeze
Belongs to collapse
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are active.
-
.by_catalog ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are by catalog.
-
.by_flag_type ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are by flag type.
-
.resolved ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are resolved.
Instance Method Summary collapse
-
#competitor_name ⇒ Object
Get the competitor's display name (from database lookup or raw seller ID).
-
#competitor_storefront_url ⇒ Object
Get the Amazon storefront URL for the competitor.
-
#known_competitor? ⇒ Boolean
Check if this is a known/named competitor.
- #resolve!(resolved_by: nil) ⇒ Object
- #resolved? ⇒ Boolean
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.active ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are active. Active Record Scope
42 |
# File 'app/models/amazon_catalog_item_flag.rb', line 42 scope :active, -> { where(resolved_at: nil) } |
.by_catalog ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are by catalog. Active Record Scope
45 |
# File 'app/models/amazon_catalog_item_flag.rb', line 45 scope :by_catalog, ->(catalog_id) { joins(:catalog_item).where(catalog_items: { catalog_id: catalog_id }) } |
.by_flag_type ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are by flag type. Active Record Scope
44 |
# File 'app/models/amazon_catalog_item_flag.rb', line 44 scope :by_flag_type, ->(type) { where(flag_type: type) } |
.resolved ⇒ ActiveRecord::Relation<AmazonCatalogItemFlag>
A relation of AmazonCatalogItemFlags that are resolved. Active Record Scope
43 |
# File 'app/models/amazon_catalog_item_flag.rb', line 43 scope :resolved, -> { where.not(resolved_at: nil) } |
Instance Method Details
#catalog_item ⇒ CatalogItem
39 |
# File 'app/models/amazon_catalog_item_flag.rb', line 39 belongs_to :catalog_item |
#competitor_name ⇒ Object
Get the competitor's display name (from database lookup or raw seller ID)
56 57 58 59 60 |
# File 'app/models/amazon_catalog_item_flag.rb', line 56 def competitor_name return nil unless competitor_seller_id.present? AmazonCompetitor.name_for(competitor_seller_id) end |
#competitor_storefront_url ⇒ Object
Get the Amazon storefront URL for the competitor
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/amazon_catalog_item_flag.rb', line 63 def competitor_storefront_url return nil unless competitor_seller_id.present? # Determine marketplace from catalog item marketplace_domain = case catalog_item&.catalog&.amazon_marketplace&.marketplace_identifier when 'ATVPDKIKX0DER' then 'amazon.com' when 'A2EUQ1WTGCTBG2' then 'amazon.ca' when 'A1F83G8C2ARO7P' then 'amazon.co.uk' when 'A1PA6795UKMFR9' then 'amazon.de' when 'A13V1IB3VIYZZH' then 'amazon.fr' when 'APJ6JRA9NG5V4' then 'amazon.it' when 'A1RKKUPIHCS9HS' then 'amazon.es' else 'amazon.com' end "https://www.#{marketplace_domain}/sp?seller=#{competitor_seller_id}" end |
#known_competitor? ⇒ Boolean
Check if this is a known/named competitor
82 83 84 85 86 |
# File 'app/models/amazon_catalog_item_flag.rb', line 82 def known_competitor? return false unless competitor_seller_id.present? AmazonCompetitor.named.exists?(seller_id: competitor_seller_id) end |
#resolve!(resolved_by: nil) ⇒ Object
51 52 53 |
# File 'app/models/amazon_catalog_item_flag.rb', line 51 def resolve!(resolved_by: nil) update!(resolved_at: Time.current, resolved_by: resolved_by) end |
#resolved? ⇒ Boolean
47 48 49 |
# File 'app/models/amazon_catalog_item_flag.rb', line 47 def resolved? resolved_at.present? end |
#resolved_by ⇒ EmployeeRecord
40 |
# File 'app/models/amazon_catalog_item_flag.rb', line 40 belongs_to :resolved_by, class_name: 'EmployeeRecord', optional: true |