diff --git a/lib/beyond_api/concerns/connection.rb b/lib/beyond_api/concerns/connection.rb index c80fe6d..1d092bb 100644 --- a/lib/beyond_api/concerns/connection.rb +++ b/lib/beyond_api/concerns/connection.rb @@ -46,6 +46,15 @@ def delete(path, params = {}, body = {}) end end + def patch(path, body = {}, params = {}) + handle_request do + agent.patch(path, body) do |request| + request.params = parse_request(params) + request.body = parse_request(body) + end + end + end + def upload_file(path, file_path, content_type, params = {}) handle_request do agent.post(path) do |request| diff --git a/lib/beyond_api/services/product_management/product.rb b/lib/beyond_api/services/product_management/product.rb index c307520..d5736b6 100644 --- a/lib/beyond_api/services/product_management/product.rb +++ b/lib/beyond_api/services/product_management/product.rb @@ -368,6 +368,27 @@ def remove_tags_from_products(ids, tags) } delete('products/batch/tags', {}, body) end + + # Update variation properties of a product. + # + # @see https://developer.epages.com/beyond-docs/#update_variation_properties + # + # @param id [String] the product UUID + # @param body [Hash] the request body containing variation properties + # + # @return [Hash] + # + # @example + # variation_properties = [ + # { property: 'salesPrice', enabled: true }, + # { property: 'listPrice', enabled: true }, + # { property: 'manufacturerPrice', enabled: true }, + # { property: 'productIdentifiers', enabled: true }, + # { property: 'defaultImage', enabled: true }, + # ] + def update_variation_properties(id, body) + patch("products/#{id}/variation-properties", body) + end end end end diff --git a/lib/beyond_api/services/product_management/variation.rb b/lib/beyond_api/services/product_management/variation.rb index f7fffaf..f29937d 100644 --- a/lib/beyond_api/services/product_management/variation.rb +++ b/lib/beyond_api/services/product_management/variation.rb @@ -21,6 +21,43 @@ class Variation < BaseService def all(id, params = {}) get("products/#{id}/variations", params) end + + # Update a variation partially with json content type. + # + # @see https://developer.epages.com/beyond-docs/#update_variation_partially_json + # + # @param id [String] the product UUID + # @param variation_id [String] the variation UUID + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # variation = { + # sales_price: { + # tax_model: "GROSS", + # amount: 29.99, + # currency: "EUR" + # }, + # list_price: { + # tax_model: "GROSS", + # amount: 39.99, + # currency: "EUR" + # }, + # manufacturer_price: { + # tax_model: "GROSS", + # amount: 40.99, + # currency: "EUR" + # }, + # sku: "1010" + # } + # @client.update('4125b993-49fc-47c8-b9b3-76d8871e4e06', + # 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', + # variation) + # + def update(id, variation_id, body) + patch("products/#{id}/variations/#{variation_id}", body) + end end end end