mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
28 lines
720 B
Ruby
28 lines
720 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class ShippingRate < ApplicationRecord
|
|
self.belongs_to_required_by_default = false
|
|
|
|
belongs_to :shipment, class_name: 'Spree::Shipment'
|
|
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
|
|
|
scope :frontend,
|
|
-> {
|
|
includes(:shipping_method).
|
|
merge(ShippingMethod.frontend).
|
|
references(:shipping_method).
|
|
order("cost ASC")
|
|
}
|
|
|
|
delegate :order, :currency, to: :shipment
|
|
delegate :name, to: :shipping_method
|
|
|
|
def display_price
|
|
Spree::Money.new(cost, { currency: })
|
|
end
|
|
|
|
alias_method :display_cost, :display_price
|
|
end
|
|
end
|