mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
33 lines
906 B
Ruby
33 lines
906 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class ShippingRate < ApplicationRecord
|
|
belongs_to :shipment, class_name: 'Spree::Shipment'
|
|
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
|
|
|
scope :frontend,
|
|
-> {
|
|
includes(:shipping_method).
|
|
where(ShippingMethod.on_frontend_query).
|
|
references(:shipping_method).
|
|
order("cost ASC")
|
|
}
|
|
scope :backend,
|
|
-> {
|
|
includes(:shipping_method).
|
|
where(ShippingMethod.on_backend_query).
|
|
references(:shipping_method).
|
|
order("cost ASC")
|
|
}
|
|
|
|
delegate :order, :currency, to: :shipment
|
|
delegate :name, to: :shipping_method
|
|
|
|
def display_price
|
|
Spree::Money.new(cost, { currency: currency })
|
|
end
|
|
|
|
alias_method :display_cost, :display_price
|
|
end
|
|
end
|