Class: AmazonAPlusContent

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/amazon_a_plus_content.rb

Overview

== Schema Information

Table name: amazon_a_plus_contents
Database name: primary

id :bigint not null, primary key
amazon_status :string
asin :string(10) not null
content_data :jsonb not null
content_reference_key :string
content_sub_type :string
content_type :string
last_status_check_at :datetime
locale :string not null
page_name :string
status :string default("draft")
created_at :datetime not null
updated_at :datetime not null
amazon_content_id :string
amazon_marketplace_id :bigint
catalog_item_id :bigint
marketplace_id :string not null

Indexes

index_amazon_a_plus_contents_on_amazon_marketplace_id (amazon_marketplace_id)
index_amazon_a_plus_contents_on_asin_marketplace_locale (asin,marketplace_id,locale) UNIQUE
index_amazon_a_plus_contents_on_catalog_item_id (catalog_item_id)
index_amazon_a_plus_contents_on_content_reference_key (content_reference_key)
index_amazon_a_plus_contents_on_content_type (content_type)
index_amazon_a_plus_contents_on_status (status)

Foreign Keys

fk_rails_... (amazon_marketplace_id => amazon_marketplaces.id)
fk_rails_... (catalog_item_id => catalog_items.id)

Constant Summary collapse

AMAZON_LOCALE_MAPPING =

Amazon locale to our locale mapping

{
  'en_US' => 'en-US',
  'en_CA' => 'en-CA',
  'fr_CA' => 'fr-CA',
  'en_GB' => 'en-GB',
  'de_DE' => 'de-DE',
  'fr_FR' => 'fr-FR',
  'es_ES' => 'es-ES',
  'it_IT' => 'it-IT',
  'nl_NL' => 'nl-NL',
  'pl_PL' => 'pl-PL',
  'sv_SE' => 'sv-SE',
  'ja_JP' => 'ja-JP',
  'pt_BR' => 'pt-BR',
  'ar_SA' => 'ar-SA',
  'tr_TR' => 'tr-TR',
  'hi_IN' => 'hi-IN',
  'en_AU' => 'en-AU',
  'en_AE' => 'en-AE'
}.freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#asinObject (readonly)



45
# File 'app/models/amazon_a_plus_content.rb', line 45

validates :asin, presence: true, length: { is: 10 }

#content_dataObject (readonly)



48
# File 'app/models/amazon_a_plus_content.rb', line 48

validates :content_data, presence: true

#content_reference_keyObject (readonly)



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

validates :content_reference_key, presence: true

#content_typeObject (readonly)



50
# File 'app/models/amazon_a_plus_content.rb', line 50

validates :content_type, presence: true

#localeObject (readonly)



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

validates :locale, presence: true

#marketplace_idObject (readonly)



46
# File 'app/models/amazon_a_plus_content.rb', line 46

validates :marketplace_id, presence: true

Class Method Details

.activeActiveRecord::Relation<AmazonAPlusContent>

A relation of AmazonAPlusContents that are active. Active Record Scope

Returns:

See Also:



65
# File 'app/models/amazon_a_plus_content.rb', line 65

scope :active, -> { where(status: %w[submitted approved]) }

.amazon_to_our_locale(amazon_locale) ⇒ Object



89
90
91
# File 'app/models/amazon_a_plus_content.rb', line 89

def self.amazon_to_our_locale(amazon_locale)
  AMAZON_LOCALE_MAPPING[amazon_locale] || amazon_locale
end

.available_locales_for_marketplace(marketplace_id) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/amazon_a_plus_content.rb', line 97

def self.available_locales_for_marketplace(marketplace_id)
  case marketplace_id
  when 'ATVPDKIKX0DER' # US
    %w[en_US]
  when 'A2EUQ1WTGCTBG2' # Canada
    %w[en_CA fr_CA]
  when 'A1F83G8C2ARO7P' # UK
    %w[en_GB]
  when 'A1PA6795UKMFR9' # Germany
    %w[de_DE]
  when 'A13V1IB3VIYZZH' # France
    %w[fr_FR]
  when 'A1RKKUPIHCS9HS' # Spain
    %w[es_ES]
  when 'APJ6JRA9NG5V4' # Italy
    %w[it_IT]
  when 'A1805IZSGTT6HS' # Netherlands
    %w[nl_NL]
  when 'A1C3SOZRARQ6R3' # Poland
    %w[pl_PL]
  when 'A2NODRKZPJ5A4Y' # Sweden
    %w[sv_SE]
  when 'A1VC38T7YXB528' # Japan
    %w[ja_JP]
  when 'A2Q3Y263D00KWC' # Brazil
    %w[pt_BR]
  when 'AMEN7PMS3EDWL' # Belgium
    %w[fr_FR nl_NL]
  else
    %w[en_US]
  end
end

.for_asinActiveRecord::Relation<AmazonAPlusContent>

A relation of AmazonAPlusContents that are for asin. Active Record Scope

Returns:

See Also:



63
# File 'app/models/amazon_a_plus_content.rb', line 63

scope :for_asin, ->(asin) { where(asin: asin) }

.for_localeActiveRecord::Relation<AmazonAPlusContent>

A relation of AmazonAPlusContents that are for locale. Active Record Scope

Returns:

See Also:



64
# File 'app/models/amazon_a_plus_content.rb', line 64

scope :for_locale, ->(locale) { where(locale: locale) }

.for_marketplaceActiveRecord::Relation<AmazonAPlusContent>

A relation of AmazonAPlusContents that are for marketplace. Active Record Scope

Returns:

See Also:



62
# File 'app/models/amazon_a_plus_content.rb', line 62

scope :for_marketplace, ->(marketplace_id) { where(marketplace_id: marketplace_id) }

.our_to_amazon_locale(our_locale) ⇒ Object



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

def self.our_to_amazon_locale(our_locale)
  AMAZON_LOCALE_MAPPING.key(our_locale) || our_locale
end

Instance Method Details

#amazon_localeObject



146
147
148
# File 'app/models/amazon_a_plus_content.rb', line 146

def amazon_locale
  locale
end

#amazon_marketplaceAmazonMarketplace



43
# File 'app/models/amazon_a_plus_content.rb', line 43

belongs_to :amazon_marketplace, optional: true

#catalog_itemCatalogItem



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

belongs_to :catalog_item, optional: true

#catalog_item_nameObject



138
139
140
# File 'app/models/amazon_a_plus_content.rb', line 138

def catalog_item_name
  catalog_item&.name || "ASIN: #{asin}"
end

#has_content?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'app/models/amazon_a_plus_content.rb', line 130

def has_content?
  content_reference_key.present?
end

#marketplace_nameObject



134
135
136
# File 'app/models/amazon_a_plus_content.rb', line 134

def marketplace_name
  amazon_marketplace&.name || marketplace_id
end

#our_localeObject



142
143
144
# File 'app/models/amazon_a_plus_content.rb', line 142

def our_locale
  self.class.amazon_to_our_locale(locale)
end