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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_asinActiveRecord::Relation<Models::ItemAmazonHelper>

A relation of Models::ItemAmazonHelpers that are with asin. Active Record Scope

Returns:

See Also:



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_profilesObject

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_descriptionObject



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_1Object



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_2Object



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_3Object



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_4Object



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_5Object



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_6Object



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_7Object



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_8Object



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_9Object



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_featuresObject



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_keywordObject



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

Returns:

See Also:



11
# File 'app/concerns/models/item_amazon_helper.rb', line 11

has_many :amazon_marketplaces, -> { distinct }, through: :catalog_items

#amazon_product_typesObject



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_keywordsObject



43
44
45
# File 'app/concerns/models/item_amazon_helper.rb', line 43

def amazon_target_keywords
  spec_output(:amazon_target_keywords)
end

#amazon_titleObject



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_codesActiveRecord::Relation<AmazonTransparencyCode>

Returns:

See Also:



10
# File 'app/concerns/models/item_amazon_helper.rb', line 10

has_many :amazon_transparency_codes, inverse_of: :item, dependent: :destroy

#amazon_variationAmazonVariation



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_amazonObject



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

Returns:

  • (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_fieldsObject



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_asinsObject



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_amazonObject



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