Skip to content

Commit 066850f

Browse files
committed
Enable API support for primary taxon
Allows access to the newly added attribute through existing product APIs.
1 parent 1c98299 commit 066850f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

api/lib/spree/api_configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ApiConfiguration < Preferences::Configuration
77
preference :product_attributes, :array, default: [
88
:id, :name, :description, :available_on,
99
:slug, :meta_description, :meta_keywords, :shipping_category_id,
10-
:taxon_ids, :total_on_hand, :meta_title
10+
:taxon_ids, :total_on_hand, :meta_title, :primary_taxon_id
1111
]
1212

1313
preference :product_property_attributes, :array, default: [:id, :product_id, :property_id, :value, :property_name]

api/spec/requests/spree/api/products_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ module Spree::Api
316316
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
317317
end
318318

319+
it "puts primary taxon for the product" do
320+
product_data[:primary_taxon_id] = taxon_1.id.to_s
321+
post spree.api_products_path, params: { product: product_data }
322+
323+
expect(json_response["primary_taxon_id"]).to eq(taxon_1.id)
324+
end
325+
319326
# Regression test for https://github.com/spree/spree/issues/4123
320327
it "puts the created product in the given taxons" do
321328
product_data[:taxon_ids] = [taxon_1.id, taxon_2.id].join(',')
@@ -404,6 +411,13 @@ module Spree::Api
404411
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
405412
end
406413

414+
it "puts primary taxon for the updated product" do
415+
product.primary_taxon_id = taxon_2.id
416+
put spree.api_product_path(product), params: { product: { primary_taxon_id: taxon_1.id } }
417+
418+
expect(json_response["primary_taxon_id"]).to eq(taxon_1.id)
419+
end
420+
407421
# Regression test for https://github.com/spree/spree/issues/4123
408422
it "puts the created product in the given taxons" do
409423
put spree.api_product_path(product), params: { product: { taxon_ids: [taxon_1.id, taxon_2.id].join(',') } }

0 commit comments

Comments
 (0)