Module: Models::ItemAmazonHelper
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Item
- Defined in:
- app/concerns/models/item_amazon_helper.rb
Overview
Helpers for items that are (or may be) listed on Amazon.
Encapsulates Amazon-specific attribute accessors, marketplace links, image
profiles, and ASIN synchronization.
Has many collapse
-
#amazon_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
Marketplaces this item is listed in through its Amazon catalog items.
-
#amazon_transparency_codes ⇒ ActiveRecord::Relation<AmazonTransparencyCode>
The legacy item->variation link is decommissioned: Amazon parents are per-marketplace via catalog_items.variant_group_id (the VariantGroup amazon row).
Class Method Summary collapse
-
.with_asin ⇒ ActiveRecord::Relation<Models::ItemAmazonHelper>
A relation of Models::ItemAmazonHelpers that are with asin.
Instance Method Summary collapse
-
#all_amazon_image_profiles ⇒ ActiveRecord::Relation<ImageProfile>
Amazon image profiles linked to this item.
-
#amazon_description ⇒ String?
Amazon listing description for this item.
-
#amazon_description=(val) ⇒ ProductSpecification?
Sets the Amazon listing description for this item.
-
#amazon_family_items ⇒ ActiveRecord::Relation<Item>
Items that share this item's per-marketplace Amazon parent listing(s) — the VariantGroup amazon rows linked via catalog_items.variant_group_id (e.g. for image-profile fan-out across the family).
-
#amazon_feature_1 ⇒ String?
First Amazon bullet/feature for this item.
-
#amazon_feature_1=(val) ⇒ ProductSpecification?
Sets the first Amazon bullet/feature for this item.
-
#amazon_feature_2 ⇒ String?
Second Amazon bullet/feature for this item.
-
#amazon_feature_2=(val) ⇒ ProductSpecification?
Sets the second Amazon bullet/feature for this item.
-
#amazon_feature_3 ⇒ String?
Third Amazon bullet/feature for this item.
-
#amazon_feature_3=(val) ⇒ ProductSpecification?
Sets the third Amazon bullet/feature for this item.
-
#amazon_feature_4 ⇒ String?
Fourth Amazon bullet/feature for this item.
-
#amazon_feature_4=(val) ⇒ ProductSpecification?
Sets the fourth Amazon bullet/feature for this item.
-
#amazon_feature_5 ⇒ String?
Fifth Amazon bullet/feature for this item.
-
#amazon_feature_5=(val) ⇒ ProductSpecification?
Sets the fifth Amazon bullet/feature for this item.
-
#amazon_feature_6 ⇒ String?
Sixth Amazon bullet/feature for this item.
-
#amazon_feature_6=(val) ⇒ ProductSpecification?
Sets the sixth Amazon bullet/feature for this item.
-
#amazon_feature_7 ⇒ String?
Seventh Amazon bullet/feature for this item.
-
#amazon_feature_7=(val) ⇒ ProductSpecification?
Sets the seventh Amazon bullet/feature for this item.
-
#amazon_feature_8 ⇒ String?
Eighth Amazon bullet/feature for this item.
-
#amazon_feature_8=(val) ⇒ ProductSpecification?
Sets the eighth Amazon bullet/feature for this item.
-
#amazon_feature_9 ⇒ String?
Ninth Amazon bullet/feature for this item.
-
#amazon_feature_9=(val) ⇒ ProductSpecification?
Sets the ninth Amazon bullet/feature for this item.
-
#amazon_features ⇒ Array<String>
All populated Amazon bullet/features for this item.
-
#amazon_generic_keyword ⇒ String?
Generic search keywords for the Amazon listing.
-
#amazon_generic_keyword=(val) ⇒ ProductSpecification?
Sets the generic search keywords for the Amazon listing.
-
#amazon_product_types ⇒ Array<String>
Desired Amazon product types across this item's catalog items.
-
#amazon_target_keywords ⇒ String?
Target keywords for the Amazon listing.
-
#amazon_title ⇒ String?
Amazon listing title for this item.
-
#amazon_title=(val) ⇒ ProductSpecification?
Sets the Amazon listing title for this item.
-
#amazon_title_differentiation ⇒ String?
Title differentiation text for the Amazon listing.
-
#amazon_title_differentiation=(val) ⇒ ProductSpecification?
Sets the title differentiation text for the Amazon listing.
-
#create_or_set_amazon_spec_value(name:, text_blurb:, locale: Mobility.locale, skip_spec_refresh: true, link_to_product_line: false) ⇒ ProductSpecification?
Creates or updates an Amazon-specific product specification.
-
#description_for_amazon ⇒ String?
Description to use for the Amazon listing, falling back to the public description.
-
#is_amazon_item? ⇒ Boolean
Whether this item has Amazon listing data.
-
#reset_amazon_fields ⇒ Integer
Clears Amazon-specific product specifications from this item.
-
#sync_amazon_asins ⇒ void
Propagates this item's ASIN to its Amazon catalog items after a save.
-
#title_for_amazon ⇒ String
Title to use for the Amazon listing, falling back to the public name.
Class Method Details
.with_asin ⇒ ActiveRecord::Relation<Models::ItemAmazonHelper>
A relation of Models::ItemAmazonHelpers that are with asin. Active Record Scope
14 |
# File 'app/concerns/models/item_amazon_helper.rb', line 14 scope :with_asin, -> { where.not(amazon_asin: nil) } |
Instance Method Details
#all_amazon_image_profiles ⇒ ActiveRecord::Relation<ImageProfile>
Amazon image profiles linked to this item.
61 62 63 |
# File 'app/concerns/models/item_amazon_helper.rb', line 61 def all_amazon_image_profiles image_profiles.amazon_image_profiles.image_order.joins(:image).includes(:image) end |
#amazon_description ⇒ String?
Amazon listing description for this item.
120 121 122 |
# File 'app/concerns/models/item_amazon_helper.rb', line 120 def amazon_description spec_output(:amazon_description) end |
#amazon_description=(val) ⇒ ProductSpecification?
Sets the Amazon listing description for this item.
128 129 130 |
# File 'app/concerns/models/item_amazon_helper.rb', line 128 def amazon_description=(val) create_or_set_amazon_spec_value(name: 'Description', text_blurb: val) end |
#amazon_family_items ⇒ ActiveRecord::Relation<Item>
Items that share this item's per-marketplace Amazon parent listing(s) — the
VariantGroup amazon rows linked via catalog_items.variant_group_id (e.g. for
image-profile fan-out across the family). Distinct from Item#variant_group,
which is the item's channel-agnostic DEFAULT family.
39 40 41 42 43 44 |
# File 'app/concerns/models/item_amazon_helper.rb', line 39 def amazon_family_items group_ids = catalog_items.where.not(variant_group_id: nil).distinct.pluck(:variant_group_id) return Item.none if group_ids.empty? Item.where(id: CatalogItem.where(variant_group_id: group_ids).joins(:store_item).distinct.select('store_items.item_id')) end |
#amazon_feature_1 ⇒ String?
First Amazon bullet/feature for this item.
135 136 137 |
# File 'app/concerns/models/item_amazon_helper.rb', line 135 def amazon_feature_1 spec_output(:amazon_feature_1) end |
#amazon_feature_1=(val) ⇒ ProductSpecification?
Sets the first Amazon bullet/feature for this item.
143 144 145 |
# File 'app/concerns/models/item_amazon_helper.rb', line 143 def amazon_feature_1=(val) create_or_set_amazon_spec_value(name: 'Feature 1', text_blurb: val) end |
#amazon_feature_2 ⇒ String?
Second Amazon bullet/feature for this item.
150 151 152 |
# File 'app/concerns/models/item_amazon_helper.rb', line 150 def amazon_feature_2 spec_output(:amazon_feature_2) end |
#amazon_feature_2=(val) ⇒ ProductSpecification?
Sets the second Amazon bullet/feature for this item.
158 159 160 |
# File 'app/concerns/models/item_amazon_helper.rb', line 158 def amazon_feature_2=(val) create_or_set_amazon_spec_value(name: 'Feature 2', text_blurb: val) end |
#amazon_feature_3 ⇒ String?
Third Amazon bullet/feature for this item.
165 166 167 |
# File 'app/concerns/models/item_amazon_helper.rb', line 165 def amazon_feature_3 spec_output(:amazon_feature_3) end |
#amazon_feature_3=(val) ⇒ ProductSpecification?
Sets the third Amazon bullet/feature for this item.
173 174 175 |
# File 'app/concerns/models/item_amazon_helper.rb', line 173 def amazon_feature_3=(val) create_or_set_amazon_spec_value(name: 'Feature 3', text_blurb: val) end |
#amazon_feature_4 ⇒ String?
Fourth Amazon bullet/feature for this item.
180 181 182 |
# File 'app/concerns/models/item_amazon_helper.rb', line 180 def amazon_feature_4 spec_output(:amazon_feature_4) end |
#amazon_feature_4=(val) ⇒ ProductSpecification?
Sets the fourth Amazon bullet/feature for this item.
188 189 190 |
# File 'app/concerns/models/item_amazon_helper.rb', line 188 def amazon_feature_4=(val) create_or_set_amazon_spec_value(name: 'Feature 4', text_blurb: val) end |
#amazon_feature_5 ⇒ String?
Fifth Amazon bullet/feature for this item.
195 196 197 |
# File 'app/concerns/models/item_amazon_helper.rb', line 195 def amazon_feature_5 spec_output(:amazon_feature_5) end |
#amazon_feature_5=(val) ⇒ ProductSpecification?
Sets the fifth Amazon bullet/feature for this item.
203 204 205 |
# File 'app/concerns/models/item_amazon_helper.rb', line 203 def amazon_feature_5=(val) create_or_set_amazon_spec_value(name: 'Feature 5', text_blurb: val) end |
#amazon_feature_6 ⇒ String?
Sixth Amazon bullet/feature for this item.
210 211 212 |
# File 'app/concerns/models/item_amazon_helper.rb', line 210 def amazon_feature_6 spec_output(:amazon_feature_6) end |
#amazon_feature_6=(val) ⇒ ProductSpecification?
Sets the sixth Amazon bullet/feature for this item.
218 219 220 |
# File 'app/concerns/models/item_amazon_helper.rb', line 218 def amazon_feature_6=(val) create_or_set_amazon_spec_value(name: 'Feature 6', text_blurb: val) end |
#amazon_feature_7 ⇒ String?
Seventh Amazon bullet/feature for this item.
225 226 227 |
# File 'app/concerns/models/item_amazon_helper.rb', line 225 def amazon_feature_7 spec_output(:amazon_feature_7) end |
#amazon_feature_7=(val) ⇒ ProductSpecification?
Sets the seventh Amazon bullet/feature for this item.
233 234 235 |
# File 'app/concerns/models/item_amazon_helper.rb', line 233 def amazon_feature_7=(val) create_or_set_amazon_spec_value(name: 'Feature 7', text_blurb: val) end |
#amazon_feature_8 ⇒ String?
Eighth Amazon bullet/feature for this item.
240 241 242 |
# File 'app/concerns/models/item_amazon_helper.rb', line 240 def amazon_feature_8 spec_output(:amazon_feature_8) end |
#amazon_feature_8=(val) ⇒ ProductSpecification?
Sets the eighth Amazon bullet/feature for this item.
248 249 250 |
# File 'app/concerns/models/item_amazon_helper.rb', line 248 def amazon_feature_8=(val) create_or_set_amazon_spec_value(name: 'Feature 8', text_blurb: val) end |
#amazon_feature_9 ⇒ String?
Ninth Amazon bullet/feature for this item.
255 256 257 |
# File 'app/concerns/models/item_amazon_helper.rb', line 255 def amazon_feature_9 spec_output(:amazon_feature_9) end |
#amazon_feature_9=(val) ⇒ ProductSpecification?
Sets the ninth Amazon bullet/feature for this item.
263 264 265 |
# File 'app/concerns/models/item_amazon_helper.rb', line 263 def amazon_feature_9=(val) create_or_set_amazon_spec_value(name: 'Feature 9', text_blurb: val) end |
#amazon_features ⇒ Array<String>
All populated Amazon bullet/features for this item.
270 271 272 |
# File 'app/concerns/models/item_amazon_helper.rb', line 270 def amazon_features [amazon_feature_1, amazon_feature_2, amazon_feature_3, amazon_feature_4, amazon_feature_5, amazon_feature_6, amazon_feature_7, amazon_feature_8, amazon_feature_9].filter_map(&:presence).uniq end |
#amazon_generic_keyword ⇒ String?
Generic search keywords for the Amazon listing.
98 99 100 |
# File 'app/concerns/models/item_amazon_helper.rb', line 98 def amazon_generic_keyword spec_output(:amazon_keywords) || spec_output(:amazon_generic_keyword) end |
#amazon_generic_keyword=(val) ⇒ ProductSpecification?
Sets the generic search keywords for the Amazon listing.
113 114 115 |
# File 'app/concerns/models/item_amazon_helper.rb', line 113 def amazon_generic_keyword=(val) create_or_set_amazon_spec_value(name: 'Generic Keyword', text_blurb: val) end |
#amazon_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
Marketplaces this item is listed in through its Amazon catalog items.
23 |
# File 'app/concerns/models/item_amazon_helper.rb', line 23 has_many :amazon_marketplaces, -> { distinct }, through: :catalog_items |
#amazon_product_types ⇒ Array<String>
Desired Amazon product types across this item's catalog items.
291 292 293 |
# File 'app/concerns/models/item_amazon_helper.rb', line 291 def amazon_product_types catalog_items.where.not(amazon_desired_product_type: nil).distinct.order(:amazon_desired_product_type).pluck(:amazon_desired_product_type) end |
#amazon_target_keywords ⇒ String?
Target keywords for the Amazon listing.
105 106 107 |
# File 'app/concerns/models/item_amazon_helper.rb', line 105 def amazon_target_keywords spec_output(:amazon_target_keywords) end |
#amazon_title ⇒ String?
Amazon listing title for this item.
68 69 70 |
# File 'app/concerns/models/item_amazon_helper.rb', line 68 def amazon_title spec_output(:amazon_title) end |
#amazon_title=(val) ⇒ ProductSpecification?
Sets the Amazon listing title for this item.
76 77 78 |
# File 'app/concerns/models/item_amazon_helper.rb', line 76 def amazon_title=(val) create_or_set_amazon_spec_value(name: 'Title', text_blurb: val) end |
#amazon_title_differentiation ⇒ String?
Title differentiation text for the Amazon listing.
83 84 85 |
# File 'app/concerns/models/item_amazon_helper.rb', line 83 def amazon_title_differentiation spec_output(:amazon_title_differentiation) end |
#amazon_title_differentiation=(val) ⇒ ProductSpecification?
Sets the title differentiation text for the Amazon listing.
91 92 93 |
# File 'app/concerns/models/item_amazon_helper.rb', line 91 def amazon_title_differentiation=(val) create_or_set_amazon_spec_value(name: 'Title Differentiation', text_blurb: val) end |
#amazon_transparency_codes ⇒ ActiveRecord::Relation<AmazonTransparencyCode>
The legacy item->variation link is decommissioned: Amazon parents are
per-marketplace via catalog_items.variant_group_id (the VariantGroup amazon
row). The historical values are preserved on the renamed
items.legacy_amazon_variation_id column, but there is intentionally NO
association for them — calling item.amazon_variation now raises NoMethodError
so accidental use fails loudly. (See RenameItemsAmazonVariationIdToLegacy.)
21 |
# File 'app/concerns/models/item_amazon_helper.rb', line 21 has_many :amazon_transparency_codes, inverse_of: :item, dependent: :destroy |
#create_or_set_amazon_spec_value(name:, text_blurb:, locale: Mobility.locale, skip_spec_refresh: true, link_to_product_line: false) ⇒ ProductSpecification?
Creates or updates an Amazon-specific product specification.
54 55 56 |
# File 'app/concerns/models/item_amazon_helper.rb', line 54 def create_or_set_amazon_spec_value(name:, text_blurb:, locale: Mobility.locale, skip_spec_refresh: true, link_to_product_line: false) create_or_set_spec_value(grouping: 'X-Amazon', text_blurb:, name:, locale:, skip_spec_refresh:, link_to_product_line:) end |
#description_for_amazon ⇒ String?
Description to use for the Amazon listing, falling back to the public description.
298 299 300 |
# File 'app/concerns/models/item_amazon_helper.rb', line 298 def description_for_amazon amazon_description.presence || public_description_text.presence end |
#is_amazon_item? ⇒ Boolean
Whether this item has Amazon listing data.
277 278 279 |
# File 'app/concerns/models/item_amazon_helper.rb', line 277 def is_amazon_item? amazon_asin.present? || catalog_items.amazons.exists? end |
#reset_amazon_fields ⇒ Integer
Clears Amazon-specific product specifications from this item.
305 306 307 308 309 |
# File 'app/concerns/models/item_amazon_helper.rb', line 305 def reset_amazon_fields fields = %i[amazon_title amazon_title_differentiation amazon_description amazon_generic_keyword] fields += (1..9).to_a.map { |n| :"amazon_feature_#{n}" } direct_product_specifications.delete_by(token: fields) end |
#sync_amazon_asins ⇒ void
This method returns an undefined value.
Propagates this item's ASIN to its Amazon catalog items after a save.
314 315 316 317 318 319 320 |
# File 'app/concerns/models/item_amazon_helper.rb', line 314 def sync_amazon_asins return unless saved_change_to_amazon_asin? catalog_items.amazons.each do |ci| ci.update!(third_party_part_number: amazon_asin) end end |
#title_for_amazon ⇒ String
Title to use for the Amazon listing, falling back to the public name.
284 285 286 |
# File 'app/concerns/models/item_amazon_helper.rb', line 284 def title_for_amazon amazon_title.presence || public_name&.first(250) end |