mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-10 03:30:22 +00:00
24 lines
563 B
Ruby
24 lines
563 B
Ruby
module Spree
|
|
class Distributor < ActiveRecord::Base
|
|
self.table_name = 'distributors'
|
|
belongs_to :country
|
|
belongs_to :state
|
|
has_and_belongs_to_many :products
|
|
has_many :orders
|
|
|
|
validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
|
|
|
|
scope :by_name, order('name')
|
|
|
|
after_initialize :initialize_country
|
|
|
|
def initialize_country
|
|
self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
|
|
end
|
|
|
|
def to_param
|
|
"#{id}-#{name.parameterize}"
|
|
end
|
|
end
|
|
end
|