mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Don't try to call tag_list on just variants since that will fail. Normally, all variants of `current_order` should be extended to VariantOverrides of the current order cycle. But in development environment, it can happen that the variants are reloaded without being extended again.
30 lines
842 B
Ruby
30 lines
842 B
Ruby
class Api::VariantSerializer < ActiveModel::Serializer
|
|
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display
|
|
attributes :options_text, :on_demand, :price, :fees, :price_with_fees, :product_name
|
|
|
|
def price
|
|
object.price
|
|
end
|
|
|
|
def fees
|
|
options[:enterprise_fee_calculator].andand.indexed_fees_by_type_for(object) ||
|
|
object.fees_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)
|
|
else
|
|
object.price_with_fees(options[:current_distributor], options[:current_order_cycle])
|
|
end
|
|
end
|
|
|
|
def product_name
|
|
object.product.name
|
|
end
|
|
|
|
def tag_list
|
|
object.tag_list if object.is_a? VariantOverride
|
|
end
|
|
end
|