-
Notifications
You must be signed in to change notification settings - Fork 2
/
product.rb
176 lines (167 loc) · 5.23 KB
/
product.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class Product
attr_accessor :handle, :title, :body, :vendor, :type, :tags, :published, :option1_name, :option1_value, :option2_name, :option2_value, :option3_name, :option3_value, :variant_sku, :variant_grams, :variant_inventory_tracker, :variant_inventory_policy, :variant_inventory_quantity, :variant_fullfilment_service, :variant_price, :variant_compare_at_price, :variant_requires_shipping, :variant_taxable, :variant_barcode, :image_src, :image_alt_text, :gift_card, :google_shopping_mpn, :google_shopping_age_group, :google_shopping_gender, :google_shopping_google_product_category, :seo_title, :seo_description, :google_shopping_adwords_grouping, :google_shopping_adwords_labels, :google_shopping_condition, :google_shopping_custom_product, :google_shopping_custom_label_0, :google_shopping_custom_label_1, :google_shopping_custom_label_2, :google_shopping_custom_label_3, :google_shopping_custom_label_4, :variant_image, :variant_weight_unit
def initialize args
args.each do |k,v|
instance_variable_set("@#{k}", v) unless v.nil?
end
@keys = [:handle, :title, :body, :vendor, :type, :tags, :published, :option1_name, :option1_value, :option2_name, :option2_value, :option3_name, :option3_value, :variant_sku, :variant_grams, :variant_inventory_tracker, :variant_inventory_policy, :variant_inventory_quantity, :variant_fullfilment_service, :variant_price, :variant_compare_at_price, :variant_requires_shipping, :variant_taxable, :variant_barcode, :image_src, :image_alt_text, :gift_card, :google_shopping_mpn, :google_shopping_age_group, :google_shopping_gender, :google_shopping_google_product_category, :seo_title, :seo_description, :google_shopping_adwords_grouping, :google_shopping_adwords_labels, :google_shopping_condition, :google_shopping_custom_product, :google_shopping_custom_label_0, :google_shopping_custom_label_1, :google_shopping_custom_label_2, :google_shopping_custom_label_3, :google_shopping_custom_label_4, :variant_image, :variant_weight_unit]
populate_values @keys
end
def populate_values keys
keys.each do |k|
if !self.send("#{k}")
instance_variable_set("@#{k}", self.send("gen_#{k}"))
end
end
end
def gen_handle
@title = Faker::Commerce.product_name
return @title.downcase.gsub!(' ', '-')
end
def gen_title
return @title
end
def gen_body
return Faker::Lorem.paragraph(1)
end
def gen_vendor
return Faker::Company.name
end
def gen_type
return Faker::Commerce.department(1, true)
end
def gen_tags
return Faker::Lorem.words.join(",")
end
def gen_published
return 'TRUE'
end
def gen_option1_name
return 'Title'
end
def gen_option1_value
return 'Extra Small'
end
def gen_option2_name
return ''
end
def gen_option2_value
return ''
end
def gen_option3_name
return ''
end
def gen_option3_value
return ''
end
def gen_variant_sku
return ''
end
def gen_variant_grams
return Faker::Number.between(20, 1000)
end
def gen_variant_inventory_tracker
return ''
end
def gen_variant_inventory_quantity
return Faker::Number.within(range: 1..50)
end
def gen_variant_inventory_policy
return 'deny'
end
def gen_variant_fullfilment_service
return 'manual'
end
def gen_variant_price
return Faker::Commerce.price
end
def gen_variant_compare_at_price
return ''
end
def gen_variant_requires_shipping
return 'TRUE'
end
def gen_variant_taxable
return 'TRUE'
end
def gen_variant_barcode
return ''
end
def gen_image_src
return Faker::Placeholdit.image(size: "320x320")
end
def gen_image_alt_text
return Faker::Lorem.sentence
end
def gen_gift_card
return 'FALSE'
end
def gen_google_shopping_mpn
return Faker::Company.ein
end
def gen_google_shopping_age_group
return ['Adult', 'Child', 'Baby'].sample
end
def gen_google_shopping_gender
return ['Unisex', 'Men', 'Women'].sample
end
def gen_google_shopping_google_product_category
return Faker::Commerce.department
end
def gen_seo_title
return Faker::Lorem.sentence
end
def gen_seo_description
return Faker::Lorem.sentence
end
def gen_google_shopping_adwords_grouping
return @type
end
def gen_google_shopping_adwords_labels
return Faker::Lorem.sentence(3, true)
end
def gen_google_shopping_condition
return ['new', 'used'].sample
end
def gen_google_shopping_custom_product
return 'FALSE'
end
def gen_google_shopping_custom_label_0
return ''
end
def gen_google_shopping_custom_label_1
return ''
end
def gen_google_shopping_custom_label_2
return ''
end
def gen_google_shopping_custom_label_3
return ''
end
def gen_google_shopping_custom_label_4
return ''
end
def gen_variant_image
return ''
end
def gen_variant_weight_unit
return ''
end
def simple_product_attributes size
child = SimpleProduct.new(static_attributes(size), self)
child.attributes
end
def attributes
@keys.map{|ivar| instance_variable_get "@#{ivar}"}
end
def headers
@keys.map{|header| header.to_s.gsub('@', '').gsub('_', ' ').capitalize }
end
def static_attributes size
{
:handle => @handle,
:option1_name => @option1_name,
:option1_value => size
}
end
end