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'- MARKETPLACE_ID_CA =
Marketplace id ca.
'A2EUQ1WTGCTBG2'- MARKETPLACE_IDS_NA =
Marketplace ids na.
[MARKETPLACE_ID_US, MARKETPLACE_ID_CA].freeze
- FBA_CHANNEL_CODE_NA =
Fba channel code na.
'AMAZON_NA'- FBA_CHANNEL_CODE_EU =
Fba channel code eu.
'AMAZON_EU'
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #marketplace_identifier ⇒ String(20) readonly
- #name ⇒ String readonly
Belongs to collapse
Has many collapse
Class Method Summary collapse
- .ca_marketplace ⇒ void
-
.north_american_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
A relation of AmazonMarketplaces that are north american marketplaces.
- .select_options ⇒ void
- .us_marketplace ⇒ void
Instance Method Summary collapse
- #fba_channel_code ⇒ void
-
#iso_code ⇒ Object
Short ISO country code for compact UI labels, e.g.
-
#seller_central_catalog ⇒ Object
Seller Central (3P) catalog this marketplace lists into — the listing destination for the marketplace's AmazonVariations.
- #supports_business_offer? ⇒ Boolean
- #to_s ⇒ String
- #url_for_asin(asin) ⇒ void
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#marketplace_identifier ⇒ String(20) (readonly)
49 |
# File 'app/models/amazon_marketplace.rb', line 49 validates :marketplace_identifier, presence: true, uniqueness: true |
#name ⇒ String (readonly)
47 |
# File 'app/models/amazon_marketplace.rb', line 47 validates :name, presence: true |
Class Method Details
.ca_marketplace ⇒ void
This method returns an undefined value.
57 58 59 |
# File 'app/models/amazon_marketplace.rb', line 57 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
42 |
# File 'app/models/amazon_marketplace.rb', line 42 scope :north_american_marketplaces, -> { where(marketplace_identifier: MARKETPLACE_IDS_NA) } |
.select_options ⇒ void
This method returns an undefined value.
62 63 64 |
# File 'app/models/amazon_marketplace.rb', line 62 def self. eager_load(:country).map { |am| [am.to_s, am.id] } end |
.us_marketplace ⇒ void
This method returns an undefined value.
52 53 54 |
# File 'app/models/amazon_marketplace.rb', line 52 def self.us_marketplace find_by(marketplace_identifier: MARKETPLACE_ID_US) end |
Instance Method Details
#amazon_schemas ⇒ ActiveRecord::Relation<AmazonSchema>
39 |
# File 'app/models/amazon_marketplace.rb', line 39 has_many :amazon_schemas, dependent: :destroy, inverse_of: :amazon_marketplace |
#catalogs ⇒ ActiveRecord::Relation<Catalog>
37 |
# File 'app/models/amazon_marketplace.rb', line 37 has_many :catalogs, dependent: :nullify, inverse_of: :amazon_marketplace |
#fba_channel_code ⇒ void
This method returns an undefined value.
80 81 82 83 84 85 86 87 |
# File 'app/models/amazon_marketplace.rb', line 80 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 |
#iso_code ⇒ Object
Short ISO country code for compact UI labels, e.g. "US", "CA".
102 103 104 |
# File 'app/models/amazon_marketplace.rb', line 102 def iso_code country&.iso end |
#seller_central_catalog ⇒ Object
Seller Central (3P) catalog this marketplace lists into — the listing
destination for the marketplace's AmazonVariations. Returns nil if the
marketplace has no Seller Central catalog configured.
97 98 99 |
# File 'app/models/amazon_marketplace.rb', line 97 def seller_central_catalog catalogs.find_by(id: CatalogConstants::AMAZON_SELLER_IDS) end |
#supports_business_offer? ⇒ Boolean
75 76 77 |
# File 'app/models/amazon_marketplace.rb', line 75 def supports_business_offer? marketplace_identifier.in?(MARKETPLACE_IDS_NA) end |
#to_s ⇒ String
90 91 92 |
# File 'app/models/amazon_marketplace.rb', line 90 def to_s "#{name} - #{marketplace_identifier}" end |
#url_for_asin(asin) ⇒ void
70 71 72 |
# File 'app/models/amazon_marketplace.rb', line 70 def url_for_asin(asin) "#{url}/dp/#{asin}" end |