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 :enum 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

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#asinObject (readonly)



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

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

#content_dataObject (readonly)



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

validates :content_data, presence: true

#content_reference_keyObject (readonly)



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

validates :content_reference_key, presence: true

#content_typeObject (readonly)



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

validates :content_type, presence: true

#localeObject (readonly)



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

validates :locale, presence: true

#marketplace_idObject (readonly)



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

validates :marketplace_id, presence: true

Class Method Details

.activeActiveRecord::Relation<AmazonAPlusContent>

A relation of AmazonAPlusContents that are active. Active Record Scope

Returns:

See Also:



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

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

.amazon_to_our_locale(amazon_locale) ⇒ Object



86
87
88
# File 'app/models/amazon_a_plus_content.rb', line 86

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

.available_locales_for_marketplace(marketplace_id) ⇒ Object



94
95
96
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
# File 'app/models/amazon_a_plus_content.rb', line 94

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:



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

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:



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

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:



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

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

.our_to_amazon_locale(our_locale) ⇒ Object



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

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

Instance Method Details

#amazon_localeObject



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

def amazon_locale
  locale
end

#amazon_marketplaceAmazonMarketplace



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

belongs_to :amazon_marketplace, optional: true

#catalog_itemCatalogItem



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

belongs_to :catalog_item, optional: true

#catalog_item_nameObject



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

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

#has_content?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/amazon_a_plus_content.rb', line 127

def has_content?
  content_reference_key.present?
end

#marketplace_nameObject



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

def marketplace_name
  amazon_marketplace&.name || marketplace_id
end

#our_localeObject



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

def our_locale
  self.class.amazon_to_our_locale(locale)
end