Drop product.price from /api/ocs/:id/products

Its serializer it's only used by this endpoint and
app/assets/javascripts/templates/shop_variant.html.haml doesn't rely on
the response's product.price but the variant's price.

Because our DB schema allows NULL on spree_prices.amount, a master
variant without a price can cause the shopfront not to load products.
This was the case in
https://app.bugsnag.com/yaycode/openfoodnetwork-uk/errors/60adfcc31cf9740007f82fc9.
This commit is contained in:
Pau Perez
2021-05-28 13:01:48 +02:00
parent 0c92a594f4
commit e7166ba5d4

View File

@@ -3,7 +3,7 @@ require "open_food_network/scope_variant_to_hub"
class Api::ProductSerializer < ActiveModel::Serializer
attributes :id, :name, :permalink, :meta_keywords
attributes :group_buy, :notes, :description, :description_html
attributes :properties_with_values, :price
attributes :properties_with_values
has_many :variants, serializer: Api::VariantSerializer
has_one :master, serializer: Api::VariantSerializer
@@ -36,14 +36,6 @@ class Api::ProductSerializer < ActiveModel::Serializer
options[:master_variants][object.id].andand.first
end
def price
if options[:enterprise_fee_calculator]
object.master.price + options[:enterprise_fee_calculator].indexed_fees_for(object.master)
else
object.master.price_with_fees(options[:current_distributor], options[:current_order_cycle])
end
end
private
def sanitizer