diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index 0655624a0b..c9fe15504f 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -12,13 +12,17 @@ class ShopController < BaseController def products if @products = products_for_shop + enterprise_fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new current_distributor, current_order_cycle + render status: 200, json: ActiveModel::ArraySerializer.new(@products, each_serializer: Api::ProductSerializer, current_order_cycle: current_order_cycle, current_distributor: current_distributor, variants: variants_for_shop_by_id, - master_variants: master_variants_for_shop_by_id).to_json + master_variants: master_variants_for_shop_by_id, + enterprise_fee_calculator: enterprise_fee_calculator, + ).to_json else render json: "", status: 404 diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb index 4c4aec2310..ada9d8d4f4 100644 --- a/app/serializers/api/product_serializer.rb +++ b/app/serializers/api/product_serializer.rb @@ -35,13 +35,14 @@ class Api::CachedProductSerializer < ActiveModel::Serializer attributes :properties_with_values has_many :variants, serializer: Api::VariantSerializer - has_many :taxons, serializer: Api::IdSerializer - has_many :images, serializer: Api::ImageSerializer - - has_one :supplier, serializer: Api::IdSerializer - has_one :primary_taxon, serializer: Api::TaxonSerializer has_one :master, serializer: Api::VariantSerializer + has_one :primary_taxon, serializer: Api::TaxonSerializer + has_many :taxons, serializer: Api::IdSerializer + + has_many :images, serializer: Api::ImageSerializer + has_one :supplier, serializer: Api::IdSerializer + def properties_with_values object.properties_including_inherited end diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index f995fa4345..557c87d71c 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -1,21 +1,20 @@ class Api::VariantSerializer < ActiveModel::Serializer - attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display, + attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display, :options_text, :on_demand, :price, :fees, :price_with_fees, :product_name - def price_with_fees - object.price_with_fees(options[:current_distributor], options[:current_order_cycle]) - end - def price object.price end def fees - object.fees_by_type_for(options[:current_distributor], options[:current_order_cycle]) + options[:enterprise_fee_calculator].indexed_fees_by_type_for(object) + end + + def price_with_fees + object.price + options[:enterprise_fee_calculator].indexed_fees_for(object) end def product_name object.product.name end - end