Class: AmazonMarketplace
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AmazonMarketplace
- Defined in:
- app/models/amazon_marketplace.rb
Overview
== Schema Information
Table name: amazon_marketplaces
Database name: primary
id :bigint not null, primary key
marketplace_identifier :string(20) not null
name :string not null
url :string
country_id :integer not null
Indexes
index_amazon_marketplaces_on_marketplace_identifier (marketplace_identifier) UNIQUE
Foreign Keys
fk_rails_... (country_id => countries.id)
Constant Summary collapse
- MARKETPLACE_ID_US =
Marketplace id us.
'ATVPDKIKX0DER'.freeze
- MARKETPLACE_ID_CA =
Marketplace id ca.
'A2EUQ1WTGCTBG2'.freeze
- MARKETPLACE_IDS_NA =
Marketplace ids na.
[MARKETPLACE_ID_US, MARKETPLACE_ID_CA].freeze
- FBA_CHANNEL_CODE_NA =
Fba channel code na.
'AMAZON_NA'.freeze
- FBA_CHANNEL_CODE_EU =
Fba channel code eu.
'AMAZON_EU'.freeze
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #marketplace_identifier ⇒ Object readonly
- #name ⇒ Object readonly
Belongs to collapse
Has many collapse
Class Method Summary collapse
- .ca_marketplace ⇒ Object
-
.north_american_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
A relation of AmazonMarketplaces that are north american marketplaces.
- .select_options ⇒ Object
- .us_marketplace ⇒ Object
Instance Method Summary collapse
- #fba_channel_code ⇒ Object
- #supports_business_offer? ⇒ Boolean
- #to_s ⇒ Object
- #url_for_asin(asin) ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#marketplace_identifier ⇒ Object (readonly)
43 |
# File 'app/models/amazon_marketplace.rb', line 43 validates :marketplace_identifier, presence: true, uniqueness: true |
#name ⇒ Object (readonly)
42 |
# File 'app/models/amazon_marketplace.rb', line 42 validates :name, presence: true |
Class Method Details
.ca_marketplace ⇒ Object
49 50 51 |
# File 'app/models/amazon_marketplace.rb', line 49 def self.ca_marketplace find_by(marketplace_identifier: MARKETPLACE_ID_CA) end |
.north_american_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
A relation of AmazonMarketplaces that are north american marketplaces. Active Record Scope
38 |
# File 'app/models/amazon_marketplace.rb', line 38 scope :north_american_marketplaces, -> { where(marketplace_identifier: MARKETPLACE_IDS_NA) } |
.select_options ⇒ Object
53 54 55 |
# File 'app/models/amazon_marketplace.rb', line 53 def self. eager_load(:country).map { |am| [am.to_s, am.id] } end |
.us_marketplace ⇒ Object
45 46 47 |
# File 'app/models/amazon_marketplace.rb', line 45 def self.us_marketplace find_by(marketplace_identifier: MARKETPLACE_ID_US) end |
Instance Method Details
#amazon_schemas ⇒ ActiveRecord::Relation<AmazonSchema>
35 |
# File 'app/models/amazon_marketplace.rb', line 35 has_many :amazon_schemas, dependent: :destroy, inverse_of: :amazon_marketplace |
#catalogs ⇒ ActiveRecord::Relation<Catalog>
34 |
# File 'app/models/amazon_marketplace.rb', line 34 has_many :catalogs, dependent: :nullify, inverse_of: :amazon_marketplace |
#fba_channel_code ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/amazon_marketplace.rb', line 65 def fba_channel_code # One of AMAZON_NA AMAZON_EU or AMAZON_JP per: https://developer-docs.amazon.com/sp-api/docs/mapping-product-attributes#inventory-feed-mappings if MARKETPLACE_IDS_NA.include?(marketplace_identifier) FBA_CHANNEL_CODE_NA else FBA_CHANNEL_CODE_EU end end |
#supports_business_offer? ⇒ Boolean
61 62 63 |
# File 'app/models/amazon_marketplace.rb', line 61 def supports_business_offer? marketplace_identifier.in?(MARKETPLACE_IDS_NA) end |
#to_s ⇒ Object
74 75 76 |
# File 'app/models/amazon_marketplace.rb', line 74 def to_s "#{name} - #{marketplace_identifier}" end |
#url_for_asin(asin) ⇒ Object
57 58 59 |
# File 'app/models/amazon_marketplace.rb', line 57 def url_for_asin(asin) "#{url}/dp/#{asin}" end |