Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples for product and update resources #121

Merged
merged 1 commit into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/products/brand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
end

# List brands
puts Bigcommerce::Brand.all(page: 2)
@brands = Bigcommerce::Brand.all(page: 1)

# Get a brand
puts Bigcommerce::Brand.find(10)
puts Bigcommerce::Brand.find(@brands.first.id)

# Get a count of brands
puts Bigcommerce::Brand.count
Expand Down
10 changes: 3 additions & 7 deletions examples/products/configurable_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@
config.access_token = ENV['BC_ACCESS_TOKEN']
end

@product = Bigcommerce::Product.all[0]
@product = Bigcommerce::Product.find(6)

# List configurable fields
@configurable_fields = Bigcommerce::ConfigurableField.all(@product.id)
puts @configurable_fields

# Get a configurable field
@configurable_field = @configurable_fields[0]
puts Bigcommerce::ConfigurableField.all(@product.id, @configurable_field.id)
puts Bigcommerce::ConfigurableField.all(@product.id, @configurable_fields.first)

# Get a count of configurable fields
puts Bigcommerce::ConfigurableField.count(@product.id)

# Get a count of all configurable fields for all products
puts Bigcommerce::ConfigurableField.count(@product.id)

# Delete a configurable field
puts Bigcommerce::ConfigurableField.destroy(@product.id, @configurable_field.id)
puts Bigcommerce::ConfigurableField.destroy(@product.id, @configurable_fields.first.id)

# Delete multiple configurable fields
# puts Bigcommerce::ConfigurableField.destroy_all(@product.id)
2 changes: 0 additions & 2 deletions examples/products/option_set_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
# List option set options
puts Bigcommerce::OptionSetOption.all(@option_set.id)

puts Bigcommerce::OptionSetOption.count(@option_set.id)

# Get an option set option
puts Bigcommerce::OptionSetOption.find(@option_set.id, @option_set_option.id)

Expand Down
2 changes: 1 addition & 1 deletion examples/products/product_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
config.access_token = ENV['BC_ACCESS_TOKEN']
end

@product = Bigcommerce::Product.all[0]
@product = Bigcommerce::Product.find(6)

# List product options
@product_options = Bigcommerce::ProductOption.all(@product.id)
Expand Down
33 changes: 33 additions & 0 deletions examples/products/product_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,36 @@

# List product reviews
puts Bigcommerce::ProductReview.all(@product.id)

# List product review
@product_reviews = Bigcommerce::ProductReview.all(@product.id)
puts @product_reviews

# Create a product review
@product_review = Bigcommerce::ProductReview.create(
@product.id,
author: 'Jimmy Doe',
rating: 5,
review: 'It was grrrreat!',
title: 'A+'
)
puts @product_review

# Get a product review
puts Bigcommerce::ProductReview.find(@product.id, @product_review.id)

# Update a product review
puts Bigcommerce::ProductReview.update(
@product.id,
@product_review.id,
author: 'John Doe',
rating: 4,
review: 'It was great!',
title: 'A'
)

# Delete a product review
puts Bigcommerce::ProductReview.destroy(@product.id, @product_review.id)

# Delete all product review
# puts Bigcommerce::ProductReview.destroy_all(@product.id)
10 changes: 5 additions & 5 deletions examples/products/product_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
config.access_token = ENV['BC_ACCESS_TOKEN']
end

@product = Bigcommerce::Product.all[0]
@product = Bigcommerce::Product.find(6)

# List product rules
@product_rules = Bigcommerce::ProductRule.all(@product.id)
Expand All @@ -23,8 +23,8 @@
@product.id,
conditions: [
{
product_option_id: 95,
option_value_id: 13,
product_option_id: 3,
option_value_id: 73,
sku_id: nil
}
]
Expand All @@ -40,8 +40,8 @@
@product_rule.id,
conditions: [
{
product_option_id: 95,
option_value_id: 12,
product_option_id: 3,
option_value_id: 73,
sku_id: nil
}
]
Expand Down
13 changes: 8 additions & 5 deletions examples/products/sku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
@product.id,
sku: SecureRandom.hex,
options: [
product_option_id: 95,
option_value_id: 10
product_option_id: 3,
option_value_id: 73
]
)
puts @sku
Expand All @@ -25,7 +25,10 @@
puts @skus

# Get a count of product skus
puts Bigcommerce::Sku.count
puts Bigcommerce::Sku.count(@product.id)

# Get a count of all product skus
puts Bigcommerce::Sku.count_all

# Get a product sku
puts Bigcommerce::Sku.find(@product.id, @sku.id)
Expand All @@ -36,8 +39,8 @@
@sku.id,
sku: SecureRandom.hex,
options: [
product_option_id: 95,
option_value_id: 7
product_option_id: 3,
option_value_id: 73
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ module Bigcommerce
class GoogleProductSearchMapping < Resource
include Bigcommerce::Request.new 'products/%d/googleproductsearch'

property :size
property :color
property :gender
property :enabled
property :pattern
property :material
property :age_group
property :product_id
property :category_id
property :custom_item
property :global_trade_item_number
property :manufacturer_part_number
property :gender
property :age_group
property :color
property :size
property :material
property :pattern
property :google_shopping_product_category_path

def self.all(product_id)
get path.build(product_id)
Expand Down
1 change: 1 addition & 0 deletions lib/bigcommerce/resources/products/option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class OptionValue < Resource
property :label
property :sort_order
property :value
property :is_default
end
end
122 changes: 61 additions & 61 deletions lib/bigcommerce/resources/products/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,88 @@ class Product < Resource
include Bigcommerce::ResourceActions.new uri: 'products/%d'

property :id
property :count
property :keyword_filter
property :sku
property :upc
property :name
property :skus
property :type
property :sku
property :description
property :search_keywords
property :availability_description
property :brand
property :depth
property :price
property :rules
property :width
property :height
property :images
property :videos
property :weight
property :options
property :brand_id
property :warranty
property :condition
property :downloads
property :tax_class
property :categories
property :cost_price
property :retail_price
property :custom_url
property :is_visible
property :option_set
property :page_title
property :sale_price
property :calculated_price
property :sort_order
property :is_visible
property :is_featured
property :related_products
property :inventory_level
property :inventory_warning_level
property :warranty
property :weight
property :width
property :height
property :depth
property :fixed_cost_shipping_price
property :is_free_shipping
property :inventory_tracking
property :rating_total
property :rating_count
property :total_sold
property :date_created
property :brand_id
property :view_count
property :page_title
property :meta_keywords
property :meta_description
property :description
property :is_featured
property :layout_file
property :is_price_hidden
property :price_hidden_label
property :categories
property :availability
property :date_created
property :rating_count
property :rating_total
property :retail_price
property :tax_class_id
property :custom_fields
property :date_modified
property :event_date_field_name
property :meta_keywords
property :option_set_id
property :discount_rules
property :event_date_end
property :keyword_filter
property :event_date_type
property :inventory_level
property :is_price_hidden
property :open_graph_type
property :search_keywords
property :calculated_price
property :event_date_start
property :event_date_end
property :is_free_shipping
property :is_preorder_only
property :meta_description
property :open_graph_title
property :preorder_message
property :related_products
property :bin_picking_number
property :date_last_imported
property :inventory_tracking
property :is_condition_shown
property :myob_asset_account
property :option_set_display
property :price_hidden_label
property :configurable_fields
property :myob_income_account
property :myob_expense_account
property :peachtree_gl_account
property :condition
property :is_condition_shown
property :event_date_field_name
property :preorder_release_date
property :is_preorder_only
property :preorder_message
property :order_quantity_minimum
property :order_quantity_maximum
property :open_graph_type
property :open_graph_title
property :open_graph_description
property :order_quantity_maximum
property :order_quantity_minimum
property :inventory_warning_level
property :is_open_graph_thumbnail
property :upc
property :date_last_imported
property :option_set_id
property :tax_class_id
property :option_set_display
property :bin_picking_number
property :custom_url
property :availability
property :brand
property :downloads
property :images
property :discount_rules
property :configurable_fields
property :custom_fields
property :videos
property :skus
property :rules
property :option_set
property :options
property :tax_class
property :availability_description
property :avalara_product_tax_code
property :fixed_cost_shipping_price
property :primary_image
property :count

def self.count(params = {})
get 'products/count', params
Expand Down
6 changes: 1 addition & 5 deletions lib/bigcommerce/resources/products/product_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Bigcommerce
class ProductReview < Resource
include Bigcommerce::Request.new 'products/%d/reviews'
include Bigcommerce::SubresourceActions.new uri: 'products/%d/reviews/%d'

property :id
property :product_id
Expand All @@ -14,9 +14,5 @@ class ProductReview < Resource
property :title
property :review
property :status

def self.all(product_id)
get path.build(product_id)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe '.all' do
it 'should hit the correct path' do
expect(@product_review).to receive(:get).with('products/1/reviews')
expect(@product_review).to receive(:get).with('products/1/reviews', {})
@product_review.all params
end
end
Expand Down