mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Add fees name for a variant to its serializer
This commit is contained in:
@@ -172,6 +172,11 @@ module Spree
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for self
|
||||
end
|
||||
|
||||
def fees_name_by_type_for(distributor, order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.new(distributor,
|
||||
order_cycle).fees_name_by_type_for self
|
||||
end
|
||||
|
||||
def option_value(opt_name)
|
||||
option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation)
|
||||
end
|
||||
|
||||
@@ -4,7 +4,8 @@ class Api::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :is_master, :product_name, :sku,
|
||||
:options_text, :unit_value, :unit_description, :unit_to_display,
|
||||
:display_as, :display_name, :name_to_display,
|
||||
:price, :on_demand, :on_hand, :fees, :price_with_fees,
|
||||
:price, :on_demand, :on_hand,
|
||||
:fees, :fees_name, :price_with_fees,
|
||||
:tag_list, :thumb_url,
|
||||
:unit_price_price, :unit_price_unit
|
||||
|
||||
@@ -15,6 +16,10 @@ class Api::VariantSerializer < ActiveModel::Serializer
|
||||
object.fees_by_type_for(options[:current_distributor], options[:current_order_cycle])
|
||||
end
|
||||
|
||||
def fees_name
|
||||
object.fees_name_by_type_for(options[:current_distributor], options[:current_order_cycle])
|
||||
end
|
||||
|
||||
def price_with_fees
|
||||
if options[:enterprise_fee_calculator]
|
||||
object.price + options[:enterprise_fee_calculator].indexed_fees_for(object)
|
||||
|
||||
@@ -20,6 +20,7 @@ describe Api::VariantSerializer do
|
||||
:on_demand,
|
||||
:price,
|
||||
:fees,
|
||||
:fees_name,
|
||||
:price_with_fees,
|
||||
:product_name,
|
||||
:tag_list # Used to apply tag rules
|
||||
|
||||
Reference in New Issue
Block a user