Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add `options` hash to Storefront Variants API (#12974)
Damian Legawiec18c571e68309
diff --git a/api/app/serializers/spree/v2/storefront/variant_serializer.rb b/api/app/serializers/spree/v2/storefront/variant_serializer.rbindex 2c762ec6e6..02ba9bdedb 100644--- a/api/app/serializers/spree/v2/storefront/variant_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/variant_serializer.rb@@ -6,7 +6,7 @@ module Spreeset_type :variant- attributes :sku, :barcode, :weight, :height, :width, :depth, :is_master, :options_text, :public_metadata+ attributes :sku, :barcode, :weight, :height, :width, :depth, :is_master, :options_text, :options, :public_metadataattribute :purchasable do |variant|variant.purchasable?diff --git a/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rbnew file mode 100644index 0000000000..5db3a8bf93--- /dev/null+++ b/api/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb@@ -0,0 +1,44 @@+require 'spec_helper'++describe Spree::V2::Storefront::VariantSerializer do+ subject { described_class.new(variant, params: serializer_params).serializable_hash }++ include_context 'API v2 serializers params'++ let!(:variant) { create(:variant, price: 10, compare_at_price: 15) }++ it 'returns expected attributes' do+ expect(subject[:data][:attributes]).to include(+ sku: variant.sku,+ barcode: variant.barcode,+ weight: variant.weight,+ height: variant.height,+ width: variant.width,+ depth: variant.depth,+ is_master: variant.is_master,+ options_text: variant.options_text,+ options: variant.options,+ public_metadata: variant.public_metadata,+ purchasable: variant.purchasable?,+ in_stock: variant.in_stock?,+ backorderable: variant.backorderable?,+ currency: currency,+ price: BigDecimal(10),+ display_price: '$10.00',+ compare_at_price: BigDecimal(15),+ display_compare_at_price: '$15.00'+ )+ end++ it 'returns expected relationships' do+ expect(subject[:data][:relationships]).to include(+ :product,+ :images,+ :option_values+ )+ end++ it 'returns correct type' do+ expect(subject[:data][:type]).to eq :variant+ end+enddiff --git a/docs/api-reference/storefront.yaml b/docs/api-reference/storefront.yamlindex 5564db6655..0a7a476788 100644--- a/docs/api-reference/storefront.yaml+++ b/docs/api-reference/storefront.yaml@@ -3808,6 +3808,17 @@ components:options_text:type: stringexample: 'Size: small, Color: red'+ options:+ type: array+ items:+ type: object+ properties:+ name:+ type: string+ value:+ type: string+ presentation:+ type: stringpurchasable:type: booleandescription: Indicates if Variant is in stock or backorderable@@ -4771,6 +4782,13 @@ components:depth: nullis_master: falseoptions_text: 'Color: white, Size: XS'+ options:+ - name: color+ value: white+ presentation: White+ - name: size+ value: XS+ presentation: XSpurchasable: truein_stock: truebackorderable: false@@ -5181,6 +5199,13 @@ components:depth: nullis_master: falseoptions_text: 'Color: white, Size: XS'+ options:+ - name: color+ value: white+ presentation: White+ - name: size+ value: XS+ presentation: XSpurchasable: truein_stock: truebackorderable: false@@ -5979,6 +6004,13 @@ components:depth: nullis_master: falseoptions_text: 'Color: khaki, Size: XS'+ options:+ - name: color+ value: khaki+ presentation: Khaki+ - name: size+ value: XS+ presentation: XSpurchasable: truein_stock: truebackorderable: false@@ -15064,6 +15096,13 @@ components:depth: nullis_master: falseoptions_text: 'Color: beige, Size: XS'+ options:+ - name: Color+ value: beige+ presentation: Beige+ - name: Size+ value: XS+ presentation: XSpurchasable: truein_stock: truebackorderable: false