From 63f41ec34ce980ea4ba79960a91db91c54a90fb1 Mon Sep 17 00:00:00 2001 From: Thea Choem <29684683+theachoem@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:58:25 +0700 Subject: [PATCH] close #567 add default state to product (#568) --- app/models/spree_cm_commissioner/product_decorator.rb | 2 ++ .../spree/v2/storefront/product_serializer_decorator.rb | 2 ++ .../spree/v2/storefront/product_serializer_spec.rb | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/spree_cm_commissioner/product_decorator.rb b/app/models/spree_cm_commissioner/product_decorator.rb index b6da22e88..2fa030ccd 100644 --- a/app/models/spree_cm_commissioner/product_decorator.rb +++ b/app/models/spree_cm_commissioner/product_decorator.rb @@ -17,6 +17,8 @@ def self.prepended(base) order('spree_variants.position, spree_variants.id, currency') }, source: :prices, through: :variants_including_master + base.has_one :default_state, through: :vendor + base.scope :min_price, lambda { |vendor| joins(:prices_including_master) .where(vendor_id: vendor.id, product_type: vendor.primary_product_type) diff --git a/app/serializers/spree/v2/storefront/product_serializer_decorator.rb b/app/serializers/spree/v2/storefront/product_serializer_decorator.rb index 10c1aa768..c3cc2b3a4 100644 --- a/app/serializers/spree/v2/storefront/product_serializer_decorator.rb +++ b/app/serializers/spree/v2/storefront/product_serializer_decorator.rb @@ -7,6 +7,8 @@ def self.prepended(base) base.has_many :product_kind_option_types, serializer: :option_type base.has_many :promoted_option_types, serializer: :option_type base.has_many :possible_promotions, serializer: ::SpreeCmCommissioner::V2::Storefront::PromotionSerializer + + base.has_one :default_state, serializer: :state end end end diff --git a/spec/serializers/spree/v2/storefront/product_serializer_spec.rb b/spec/serializers/spree/v2/storefront/product_serializer_spec.rb index d6859f06d..9a6c2768b 100644 --- a/spec/serializers/spree/v2/storefront/product_serializer_spec.rb +++ b/spec/serializers/spree/v2/storefront/product_serializer_spec.rb @@ -17,7 +17,8 @@ :variant_kind_option_types, :product_kind_option_types, :promoted_option_types, - :possible_promotions + :possible_promotions, + :default_state, ]).serializable_hash } @@ -58,7 +59,8 @@ :variant_kind_option_types, :product_kind_option_types, :promoted_option_types, - :possible_promotions + :possible_promotions, + :default_state, ) end end