Files
openfoodnetwork/engines/dfc_provider/app/services/offer_builder.rb
Maikel Linke 2465780c1c Import prices and stock levels from DFC catalog
We were already importing stock levels from offers but now we are
looking at catalog items as well.
2024-09-26 14:32:01 +10:00

36 lines
699 B
Ruby

# frozen_string_literal: true
class OfferBuilder < DfcBuilder
def self.build(variant)
id = urls.enterprise_offer_url(
enterprise_id: variant.supplier_id,
id: variant.id,
)
DataFoodConsortium::Connector::Offer.new(
id,
price: variant.price.to_f,
stockLimitation: stock_limitation(variant),
)
end
def self.apply(offer, variant)
return if offer.nil?
CatalogItemBuilder.apply_stock(offer, variant)
return if offer.price.nil?
variant.price = price(offer)
end
def self.price(offer)
# We assume same currency here:
if offer.price.respond_to?(:value)
offer.price.value
else
offer.price
end
end
end