-
Notifications
You must be signed in to change notification settings - Fork 124
/
custom_field.rb
44 lines (34 loc) · 1.03 KB
/
custom_field.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
require 'bigcommerce'
require 'securerandom'
Bigcommerce.configure do |config|
config.store_hash = ENV['BC_STORE_HASH']
config.client_id = ENV['BC_CLIENT_ID']
config.access_token = ENV['BC_ACCESS_TOKEN']
end
@product = Bigcommerce::Product.all[0]
# Create a custom field
@custom_field = Bigcommerce::CustomField.create(
@product.id,
name: SecureRandom.hex,
text: SecureRandom.hex
)
puts @custom_field
# List custom fields
puts Bigcommerce::CustomField.all(@product.id)
# Get a custom field
puts Bigcommerce::CustomField.find(@product.id, @custom_field.id)
# Get a count of custom fields
puts Bigcommerce::CustomField.count(@product.id)
# Get a count of custom fields for all products
puts Bigcommerce::CustomField.count_all
# Update a custom field
puts Bigcommerce::CustomField.update(
@product.id,
@custom_field.id,
name: ':)',
text: ':)'
)
# Delete a custom field
puts Bigcommerce::CustomField.destroy(@product.id, @custom_field.id)
# Delete multiple custom fields
# puts Bigcommerce::CustomField.destroy_all(@product.id)