Module: Models::ItemAmazonHelper

Extended by:
ActiveSupport::Concern
Includes:
Memery
Included in:
Item
Defined in:
app/concerns/models/item_amazon_helper.rb

Overview

ActiveSupport::Concern mixin: item amazon helper.

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:



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

scope :with_asin, -> { where.not(amazon_asin: nil) }

Instance Method Details

#all_amazon_image_profilesObject

Retrieve amazon image profiles linked to this item



29
30
31
# File 'app/concerns/models/item_amazon_helper.rb', line 29

def all_amazon_image_profiles
  image_profiles.amazon_image_profiles.image_order.joins(:image).includes(:image)
end

#amazon_descriptionObject



53
54
55
# File 'app/concerns/models/item_amazon_helper.rb', line 53

def amazon_description
  spec_output(:amazon_description)
end

#amazon_description=(val) ⇒ Object



57
58
59
# File 'app/concerns/models/item_amazon_helper.rb', line 57

def amazon_description=(val)
  create_or_set_amazon_spec_value(name: 'Description', text_blurb: val)
end

#amazon_feature_1Object



61
62
63
# File 'app/concerns/models/item_amazon_helper.rb', line 61

def amazon_feature_1
  spec_output(:amazon_feature_1)
end

#amazon_feature_1=(val) ⇒ Object



65
66
67
# File 'app/concerns/models/item_amazon_helper.rb', line 65

def amazon_feature_1=(val)
  create_or_set_amazon_spec_value(name: 'Feature 1', text_blurb: val)
end

#amazon_feature_2Object



69
70
71
# File 'app/concerns/models/item_amazon_helper.rb', line 69

def amazon_feature_2
  spec_output(:amazon_feature_2)
end

#amazon_feature_2=(val) ⇒ Object



73
74
75
# File 'app/concerns/models/item_amazon_helper.rb', line 73

def amazon_feature_2=(val)
  create_or_set_amazon_spec_value(name: 'Feature 2', text_blurb: val)
end

#amazon_feature_3Object



77
78
79
# File 'app/concerns/models/item_amazon_helper.rb', line 77

def amazon_feature_3
  spec_output(:amazon_feature_3)
end

#amazon_feature_3=(val) ⇒ Object



81
82
83
# File 'app/concerns/models/item_amazon_helper.rb', line 81

def amazon_feature_3=(val)
  create_or_set_amazon_spec_value(name: 'Feature 3', text_blurb: val)
end

#amazon_feature_4Object



85
86
87
# File 'app/concerns/models/item_amazon_helper.rb', line 85

def amazon_feature_4
  spec_output(:amazon_feature_4)
end

#amazon_feature_4=(val) ⇒ Object



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

def amazon_feature_4=(val)
  create_or_set_amazon_spec_value(name: 'Feature 4', text_blurb: val)
end

#amazon_feature_5Object



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

def amazon_feature_5
  spec_output(:amazon_feature_5)
end

#amazon_feature_5=(val) ⇒ Object



97
98
99
# File 'app/concerns/models/item_amazon_helper.rb', line 97

def amazon_feature_5=(val)
  create_or_set_amazon_spec_value(name: 'Feature 5', text_blurb: val)
end

#amazon_feature_6Object



101
102
103
# File 'app/concerns/models/item_amazon_helper.rb', line 101

def amazon_feature_6
  spec_output(:amazon_feature_6)
end

#amazon_feature_6=(val) ⇒ Object



105
106
107
# File 'app/concerns/models/item_amazon_helper.rb', line 105

def amazon_feature_6=(val)
  create_or_set_amazon_spec_value(name: 'Feature 6', text_blurb: val)
end

#amazon_feature_7Object



109
110
111
# File 'app/concerns/models/item_amazon_helper.rb', line 109

def amazon_feature_7
  spec_output(:amazon_feature_7)
end

#amazon_feature_7=(val) ⇒ Object



113
114
115
# File 'app/concerns/models/item_amazon_helper.rb', line 113

def amazon_feature_7=(val)
  create_or_set_amazon_spec_value(name: 'Feature 7', text_blurb: val)
end

#amazon_feature_8Object



117
118
119
# File 'app/concerns/models/item_amazon_helper.rb', line 117

def amazon_feature_8
  spec_output(:amazon_feature_8)
end

#amazon_feature_8=(val) ⇒ Object



121
122
123
# File 'app/concerns/models/item_amazon_helper.rb', line 121

def amazon_feature_8=(val)
  create_or_set_amazon_spec_value(name: 'Feature 8', text_blurb: val)
end

#amazon_feature_9Object



125
126
127
# File 'app/concerns/models/item_amazon_helper.rb', line 125

def amazon_feature_9
  spec_output(:amazon_feature_9)
end

#amazon_feature_9=(val) ⇒ Object



129
130
131
# File 'app/concerns/models/item_amazon_helper.rb', line 129

def amazon_feature_9=(val)
  create_or_set_amazon_spec_value(name: 'Feature 9', text_blurb: val)
end

#amazon_featuresObject



133
134
135
# File 'app/concerns/models/item_amazon_helper.rb', line 133

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



41
42
43
# File 'app/concerns/models/item_amazon_helper.rb', line 41

def amazon_generic_keyword
  spec_output(:amazon_keywords) || spec_output(:amazon_generic_keyword)
end

#amazon_generic_keyword=(val) ⇒ Object



49
50
51
# File 'app/concerns/models/item_amazon_helper.rb', line 49

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:



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

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

#amazon_product_typesObject



145
146
147
# File 'app/concerns/models/item_amazon_helper.rb', line 145

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



45
46
47
# File 'app/concerns/models/item_amazon_helper.rb', line 45

def amazon_target_keywords
  spec_output(:amazon_target_keywords)
end

#amazon_titleObject



33
34
35
# File 'app/concerns/models/item_amazon_helper.rb', line 33

def amazon_title
  spec_output(:amazon_title)
end

#amazon_title=(val) ⇒ Object



37
38
39
# File 'app/concerns/models/item_amazon_helper.rb', line 37

def amazon_title=(val)
  create_or_set_amazon_spec_value(name: 'Title', text_blurb: val)
end

#amazon_transparency_codesActiveRecord::Relation<AmazonTransparencyCode>

Returns:

See Also:



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

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

#amazon_variationAmazonVariation



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

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



24
25
26
# File 'app/concerns/models/item_amazon_helper.rb', line 24

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



149
150
151
# File 'app/concerns/models/item_amazon_helper.rb', line 149

def description_for_amazon
  amazon_description.presence || public_description_text.presence
end

#is_amazon_item?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'app/concerns/models/item_amazon_helper.rb', line 137

def is_amazon_item?
  amazon_asin.present? || catalog_items.amazons.exists?
end

#reset_amazon_fieldsObject



153
154
155
156
157
# File 'app/concerns/models/item_amazon_helper.rb', line 153

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.delete_by(token: fields)
end

#sync_amazon_asinsObject



159
160
161
162
163
164
165
# File 'app/concerns/models/item_amazon_helper.rb', line 159

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



141
142
143
# File 'app/concerns/models/item_amazon_helper.rb', line 141

def title_for_amazon
  amazon_title.presence || public_name&.first(250)
end