From 65bf73b8ca1aa8eb4f368ac9615897e831d4da95 Mon Sep 17 00:00:00 2001 From: Patrick Edelman Date: Mon, 20 Jun 2016 21:18:30 -0700 Subject: [PATCH] Update examples for product and update resources --- examples/products/brand.rb | 4 +- examples/products/configurable_field.rb | 10 +- examples/products/option_set_option.rb | 2 - examples/products/product_option.rb | 2 +- examples/products/product_review.rb | 33 +++++ examples/products/product_rule.rb | 10 +- examples/products/sku.rb | 13 +- .../products/google_product_search_mapping.rb | 13 +- .../resources/products/option_value.rb | 1 + lib/bigcommerce/resources/products/product.rb | 122 +++++++++--------- .../resources/products/product_review.rb | 6 +- .../resources/products/product_review_spec.rb | 2 +- 12 files changed, 123 insertions(+), 95 deletions(-) diff --git a/examples/products/brand.rb b/examples/products/brand.rb index 970a4e6..3f7192e 100644 --- a/examples/products/brand.rb +++ b/examples/products/brand.rb @@ -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 diff --git a/examples/products/configurable_field.rb b/examples/products/configurable_field.rb index 5c84971..34aa7bd 100644 --- a/examples/products/configurable_field.rb +++ b/examples/products/configurable_field.rb @@ -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) diff --git a/examples/products/option_set_option.rb b/examples/products/option_set_option.rb index c73a2bd..8581917 100644 --- a/examples/products/option_set_option.rb +++ b/examples/products/option_set_option.rb @@ -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) diff --git a/examples/products/product_option.rb b/examples/products/product_option.rb index b890404..524dcdd 100644 --- a/examples/products/product_option.rb +++ b/examples/products/product_option.rb @@ -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) diff --git a/examples/products/product_review.rb b/examples/products/product_review.rb index b06c9d9..dbe79c9 100644 --- a/examples/products/product_review.rb +++ b/examples/products/product_review.rb @@ -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) diff --git a/examples/products/product_rule.rb b/examples/products/product_rule.rb index d41f256..e58b6fa 100644 --- a/examples/products/product_rule.rb +++ b/examples/products/product_rule.rb @@ -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) @@ -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 } ] @@ -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 } ] diff --git a/examples/products/sku.rb b/examples/products/sku.rb index 65e1ff6..305a8ba 100644 --- a/examples/products/sku.rb +++ b/examples/products/sku.rb @@ -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 @@ -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) @@ -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 ] ) diff --git a/lib/bigcommerce/resources/products/google_product_search_mapping.rb b/lib/bigcommerce/resources/products/google_product_search_mapping.rb index 251b043..3847493 100644 --- a/lib/bigcommerce/resources/products/google_product_search_mapping.rb +++ b/lib/bigcommerce/resources/products/google_product_search_mapping.rb @@ -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) diff --git a/lib/bigcommerce/resources/products/option_value.rb b/lib/bigcommerce/resources/products/option_value.rb index 43fe487..36f1508 100644 --- a/lib/bigcommerce/resources/products/option_value.rb +++ b/lib/bigcommerce/resources/products/option_value.rb @@ -11,5 +11,6 @@ class OptionValue < Resource property :label property :sort_order property :value + property :is_default end end diff --git a/lib/bigcommerce/resources/products/product.rb b/lib/bigcommerce/resources/products/product.rb index e02262b..125dd70 100644 --- a/lib/bigcommerce/resources/products/product.rb +++ b/lib/bigcommerce/resources/products/product.rb @@ -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 diff --git a/lib/bigcommerce/resources/products/product_review.rb b/lib/bigcommerce/resources/products/product_review.rb index 37a5fce..0aed3aa 100644 --- a/lib/bigcommerce/resources/products/product_review.rb +++ b/lib/bigcommerce/resources/products/product_review.rb @@ -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 @@ -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 diff --git a/spec/bigcommerce/unit/resources/products/product_review_spec.rb b/spec/bigcommerce/unit/resources/products/product_review_spec.rb index 2dc91f3..6b9621d 100644 --- a/spec/bigcommerce/unit/resources/products/product_review_spec.rb +++ b/spec/bigcommerce/unit/resources/products/product_review_spec.rb @@ -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