mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
Adding producers to home and distributors to producers
This commit is contained in:
@@ -136,6 +136,14 @@ class Enterprise < ActiveRecord::Base
|
||||
", self.id, self.id)
|
||||
end
|
||||
|
||||
def distributors
|
||||
self.relatives.is_distributor
|
||||
end
|
||||
|
||||
def suppliers
|
||||
self.relatives.is_supplier
|
||||
end
|
||||
|
||||
def distributed_variants
|
||||
Spree::Variant.joins(:product).merge(Spree::Product.in_distributor(self)).select('spree_variants.*')
|
||||
end
|
||||
@@ -149,11 +157,17 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
|
||||
# Return all taxons for all distributed products
|
||||
def taxons
|
||||
def distributed_taxons
|
||||
Spree::Product.in_distributor(self).map do |p|
|
||||
p.taxons
|
||||
end.flatten.uniq
|
||||
end
|
||||
# Return all taxons for all supplied products
|
||||
def supplied_taxons
|
||||
Spree::Product.in_supplier(self).map do |p|
|
||||
p.taxons
|
||||
end.flatten.uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
# DON'T USE DIRECTLY - for inheritance
|
||||
attributes :name, :id
|
||||
|
||||
child :taxons => :taxons do
|
||||
attributes :name, :id
|
||||
end
|
||||
attributes :name, :id, :description
|
||||
|
||||
child :address do
|
||||
extends "json/partials/address"
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
collection Enterprise.visible.is_distributor
|
||||
extends 'json/enterprises'
|
||||
|
||||
child distributed_taxons: :taxons do
|
||||
attributes :name, :id
|
||||
end
|
||||
|
||||
child producers: :producers do
|
||||
attributes :name, :id
|
||||
node :path do |producer|
|
||||
producer_path(producer_path)
|
||||
end
|
||||
end
|
||||
|
||||
node :pickup do |hub|
|
||||
not hub.shipping_methods.where(:require_ship_address => false).empty?
|
||||
end
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
collection @producers
|
||||
extends 'json/enterprises'
|
||||
|
||||
child supplied_taxons: :taxons do
|
||||
attributes :name, :id
|
||||
end
|
||||
|
||||
child distributors: :distributors do
|
||||
attributes :name, :id
|
||||
node :path do |distributor|
|
||||
distributor_path(distributor)
|
||||
end
|
||||
end
|
||||
|
||||
node :path do |producer|
|
||||
producer_path(producer)
|
||||
end
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
%strong Shop for
|
||||
%p.trans-sentence
|
||||
{{ producer.taxons | printArrayOfObjects }}
|
||||
.columns.small-8
|
||||
About Us
|
||||
.columns.small-4
|
||||
%strong About us
|
||||
{{ producer.description }}
|
||||
.columns.small-4
|
||||
%strong Our distributors
|
||||
|
||||
.row.active_table_row.link{"ng-show" => "open()", "ng-repeat" => "hub in producer.hubs"}
|
||||
.columns.small-11
|
||||
%a{"bo-href" => "hub.path"}
|
||||
Shop at
|
||||
%strong {{ hub.name }}
|
||||
%strong {{ producer.name }}
|
||||
.columns.small-1.text-right
|
||||
%a{"bo-href" => "hub.path"}
|
||||
%i.fi-arrow-right
|
||||
|
||||
Reference in New Issue
Block a user