Class: AmazonMarketplace

Inherits:
ApplicationRecord show all
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

Belongs to collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, 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

Instance Attribute Details

#marketplace_identifierString(20) (readonly)

Returns:

  • (String(20))


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

validates :marketplace_identifier, presence: true, uniqueness: true

#nameString (readonly)

Returns:

  • (String)


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

validates :name, presence: true

Class Method Details

.ca_marketplacevoid

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_marketplacesActiveRecord::Relation<AmazonMarketplace>

A relation of AmazonMarketplaces that are north american marketplaces. Active Record Scope

Returns:

See Also:



42
# File 'app/models/amazon_marketplace.rb', line 42

scope :north_american_marketplaces, -> { where(marketplace_identifier: MARKETPLACE_IDS_NA) }

.select_optionsvoid

This method returns an undefined value.



62
63
64
# File 'app/models/amazon_marketplace.rb', line 62

def self.select_options
  eager_load(:country).map { |am| [am.to_s, am.id] }
end

.us_marketplacevoid

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_schemasActiveRecord::Relation<AmazonSchema>

Returns:



39
# File 'app/models/amazon_marketplace.rb', line 39

has_many :amazon_schemas, dependent: :destroy, inverse_of: :amazon_marketplace

#catalogsActiveRecord::Relation<Catalog>

Returns:

  • (ActiveRecord::Relation<Catalog>)


37
# File 'app/models/amazon_marketplace.rb', line 37

has_many :catalogs, dependent: :nullify, inverse_of: :amazon_marketplace

#countryCountry?

Returns:



35
# File 'app/models/amazon_marketplace.rb', line 35

belongs_to :country

#fba_channel_codevoid

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_codeObject

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_catalogObject

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

Returns:

  • (Boolean)


75
76
77
# File 'app/models/amazon_marketplace.rb', line 75

def supports_business_offer?
  marketplace_identifier.in?(MARKETPLACE_IDS_NA)
end

#to_sString

Returns:

  • (String)


90
91
92
# File 'app/models/amazon_marketplace.rb', line 90

def to_s
  "#{name} - #{marketplace_identifier}"
end

#url_for_asin(asin) ⇒ void

Parameters:

  • asin (Object)
  • asin (Object)

Returns:

  • (void)
  • (void)


70
71
72
# File 'app/models/amazon_marketplace.rb', line 70

def url_for_asin(asin)
  "#{url}/dp/#{asin}"
end