Module: Models::ItemAmazonHelper
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Item
- Defined in:
- app/concerns/models/item_amazon_helper.rb
Belongs to collapse
Has many collapse
- #amazon_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
- #amazon_transparency_codes ⇒ ActiveRecord::Relation<AmazonTransparencyCode>
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 ⇒ Object
Retrieve amazon image profiles linked to this item.
- #amazon_description ⇒ Object
- #amazon_description=(val) ⇒ Object
- #amazon_feature_1 ⇒ Object
- #amazon_feature_1=(val) ⇒ Object
- #amazon_feature_2 ⇒ Object
- #amazon_feature_2=(val) ⇒ Object
- #amazon_feature_3 ⇒ Object
- #amazon_feature_3=(val) ⇒ Object
- #amazon_feature_4 ⇒ Object
- #amazon_feature_4=(val) ⇒ Object
- #amazon_feature_5 ⇒ Object
- #amazon_feature_5=(val) ⇒ Object
- #amazon_feature_6 ⇒ Object
- #amazon_feature_6=(val) ⇒ Object
- #amazon_feature_7 ⇒ Object
- #amazon_feature_7=(val) ⇒ Object
- #amazon_feature_8 ⇒ Object
- #amazon_feature_8=(val) ⇒ Object
- #amazon_feature_9 ⇒ Object
- #amazon_feature_9=(val) ⇒ Object
- #amazon_features ⇒ Object
- #amazon_generic_keyword ⇒ Object
- #amazon_generic_keyword=(val) ⇒ Object
- #amazon_product_types ⇒ Object
- #amazon_target_keywords ⇒ Object
- #amazon_title ⇒ Object
- #amazon_title=(val) ⇒ Object
- #create_or_set_amazon_spec_value(name:, text_blurb:, locale: Mobility.locale, skip_spec_refresh: true, link_to_product_line: false) ⇒ Object
- #description_for_amazon ⇒ Object
- #is_amazon_item? ⇒ Boolean
- #reset_amazon_fields ⇒ Object
- #sync_amazon_asins ⇒ Object
- #title_for_amazon ⇒ Object
Class Method Details
.with_asin ⇒ ActiveRecord::Relation<Models::ItemAmazonHelper>
A relation of Models::ItemAmazonHelpers that are with asin. Active Record Scope
8 |
# File 'app/concerns/models/item_amazon_helper.rb', line 8 scope :with_asin, -> { where.not(amazon_asin: nil) } |
Instance Method Details
#all_amazon_image_profiles ⇒ Object
Retrieve amazon image profiles linked to this item
27 28 29 |
# File 'app/concerns/models/item_amazon_helper.rb', line 27 def all_amazon_image_profiles image_profiles.amazon_image_profiles.image_order.joins(:image).includes(:image) end |
#amazon_description ⇒ Object
51 52 53 |
# File 'app/concerns/models/item_amazon_helper.rb', line 51 def amazon_description spec_output(:amazon_description) end |
#amazon_description=(val) ⇒ Object
55 56 57 |
# File 'app/concerns/models/item_amazon_helper.rb', line 55 def amazon_description=(val) create_or_set_amazon_spec_value(name: 'Description', text_blurb: val) end |
#amazon_feature_1 ⇒ Object
59 60 61 |
# File 'app/concerns/models/item_amazon_helper.rb', line 59 def amazon_feature_1 spec_output(:amazon_feature_1) end |
#amazon_feature_1=(val) ⇒ Object
63 64 65 |
# File 'app/concerns/models/item_amazon_helper.rb', line 63 def amazon_feature_1=(val) create_or_set_amazon_spec_value(name: 'Feature 1', text_blurb: val) end |
#amazon_feature_2 ⇒ Object
67 68 69 |
# File 'app/concerns/models/item_amazon_helper.rb', line 67 def amazon_feature_2 spec_output(:amazon_feature_2) end |
#amazon_feature_2=(val) ⇒ Object
71 72 73 |
# File 'app/concerns/models/item_amazon_helper.rb', line 71 def amazon_feature_2=(val) create_or_set_amazon_spec_value(name: 'Feature 2', text_blurb: val) end |
#amazon_feature_3 ⇒ Object
75 76 77 |
# File 'app/concerns/models/item_amazon_helper.rb', line 75 def amazon_feature_3 spec_output(:amazon_feature_3) end |
#amazon_feature_3=(val) ⇒ Object
79 80 81 |
# File 'app/concerns/models/item_amazon_helper.rb', line 79 def amazon_feature_3=(val) create_or_set_amazon_spec_value(name: 'Feature 3', text_blurb: val) end |
#amazon_feature_4 ⇒ Object
83 84 85 |
# File 'app/concerns/models/item_amazon_helper.rb', line 83 def amazon_feature_4 spec_output(:amazon_feature_4) end |
#amazon_feature_4=(val) ⇒ Object
87 88 89 |
# File 'app/concerns/models/item_amazon_helper.rb', line 87 def amazon_feature_4=(val) create_or_set_amazon_spec_value(name: 'Feature 4', text_blurb: val) end |
#amazon_feature_5 ⇒ Object
91 92 93 |
# File 'app/concerns/models/item_amazon_helper.rb', line 91 def amazon_feature_5 spec_output(:amazon_feature_5) end |
#amazon_feature_5=(val) ⇒ Object
95 96 97 |
# File 'app/concerns/models/item_amazon_helper.rb', line 95 def amazon_feature_5=(val) create_or_set_amazon_spec_value(name: 'Feature 5', text_blurb: val) end |
#amazon_feature_6 ⇒ Object
99 100 101 |
# File 'app/concerns/models/item_amazon_helper.rb', line 99 def amazon_feature_6 spec_output(:amazon_feature_6) end |
#amazon_feature_6=(val) ⇒ Object
103 104 105 |
# File 'app/concerns/models/item_amazon_helper.rb', line 103 def amazon_feature_6=(val) create_or_set_amazon_spec_value(name: 'Feature 6', text_blurb: val) end |
#amazon_feature_7 ⇒ Object
107 108 109 |
# File 'app/concerns/models/item_amazon_helper.rb', line 107 def amazon_feature_7 spec_output(:amazon_feature_7) end |
#amazon_feature_7=(val) ⇒ Object
111 112 113 |
# File 'app/concerns/models/item_amazon_helper.rb', line 111 def amazon_feature_7=(val) create_or_set_amazon_spec_value(name: 'Feature 7', text_blurb: val) end |
#amazon_feature_8 ⇒ Object
115 116 117 |
# File 'app/concerns/models/item_amazon_helper.rb', line 115 def amazon_feature_8 spec_output(:amazon_feature_8) end |
#amazon_feature_8=(val) ⇒ Object
119 120 121 |
# File 'app/concerns/models/item_amazon_helper.rb', line 119 def amazon_feature_8=(val) create_or_set_amazon_spec_value(name: 'Feature 8', text_blurb: val) end |
#amazon_feature_9 ⇒ Object
123 124 125 |
# File 'app/concerns/models/item_amazon_helper.rb', line 123 def amazon_feature_9 spec_output(:amazon_feature_9) end |
#amazon_feature_9=(val) ⇒ Object
127 128 129 |
# File 'app/concerns/models/item_amazon_helper.rb', line 127 def amazon_feature_9=(val) create_or_set_amazon_spec_value(name: 'Feature 9', text_blurb: val) end |
#amazon_features ⇒ Object
131 132 133 |
# File 'app/concerns/models/item_amazon_helper.rb', line 131 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 ⇒ Object
39 40 41 |
# File 'app/concerns/models/item_amazon_helper.rb', line 39 def amazon_generic_keyword spec_output(:amazon_keywords) || spec_output(:amazon_generic_keyword) end |
#amazon_generic_keyword=(val) ⇒ Object
47 48 49 |
# File 'app/concerns/models/item_amazon_helper.rb', line 47 def amazon_generic_keyword=(val) create_or_set_amazon_spec_value(name: 'Generic Keyword', text_blurb: val) end |
#amazon_marketplaces ⇒ ActiveRecord::Relation<AmazonMarketplace>
11 |
# File 'app/concerns/models/item_amazon_helper.rb', line 11 has_many :amazon_marketplaces, -> { distinct }, through: :catalog_items |
#amazon_product_types ⇒ Object
143 144 145 |
# File 'app/concerns/models/item_amazon_helper.rb', line 143 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 ⇒ Object
43 44 45 |
# File 'app/concerns/models/item_amazon_helper.rb', line 43 def amazon_target_keywords spec_output(:amazon_target_keywords) end |
#amazon_title ⇒ Object
31 32 33 |
# File 'app/concerns/models/item_amazon_helper.rb', line 31 def amazon_title spec_output(:amazon_title) end |
#amazon_title=(val) ⇒ Object
35 36 37 |
# File 'app/concerns/models/item_amazon_helper.rb', line 35 def amazon_title=(val) create_or_set_amazon_spec_value(name: 'Title', text_blurb: val) end |
#amazon_transparency_codes ⇒ ActiveRecord::Relation<AmazonTransparencyCode>
10 |
# File 'app/concerns/models/item_amazon_helper.rb', line 10 has_many :amazon_transparency_codes, inverse_of: :item, dependent: :destroy |
#amazon_variation ⇒ AmazonVariation
9 |
# File 'app/concerns/models/item_amazon_helper.rb', line 9 belongs_to :amazon_variation, optional: true |
#create_or_set_amazon_spec_value(name:, text_blurb:, locale: Mobility.locale, skip_spec_refresh: true, link_to_product_line: false) ⇒ Object
22 23 24 |
# File 'app/concerns/models/item_amazon_helper.rb', line 22 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 ⇒ Object
147 148 149 |
# File 'app/concerns/models/item_amazon_helper.rb', line 147 def description_for_amazon amazon_description.presence || public_description_text.presence end |
#is_amazon_item? ⇒ Boolean
135 136 137 |
# File 'app/concerns/models/item_amazon_helper.rb', line 135 def is_amazon_item? amazon_asin.present? || catalog_items.amazons.exists? end |
#reset_amazon_fields ⇒ Object
151 152 153 154 155 |
# File 'app/concerns/models/item_amazon_helper.rb', line 151 def reset_amazon_fields fields = %i[amazon_title amazon_description amazon_generic_keyword] fields += (1..9).to_a.map { |n| :"amazon_feature_#{n}" } direct_product_specifications.where(token: fields).delete_all end |
#sync_amazon_asins ⇒ Object
157 158 159 160 161 162 163 |
# File 'app/concerns/models/item_amazon_helper.rb', line 157 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 ⇒ Object
139 140 141 |
# File 'app/concerns/models/item_amazon_helper.rb', line 139 def title_for_amazon amazon_title.presence || public_name&.first(250) end |