mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
enable ordering shopfront by producer id
This commit is contained in:
@@ -9,8 +9,10 @@ class Enterprise < ApplicationRecord
|
||||
preference :shopfront_message, :text, default: ""
|
||||
preference :shopfront_closed_message, :text, default: ""
|
||||
preference :shopfront_taxon_order, :string, default: ""
|
||||
preference :shopfront_producer_order, :string, default: ""
|
||||
preference :shopfront_order_cycle_order, :string, default: "orders_close_at"
|
||||
preference :show_customer_names_to_suppliers, :boolean, default: false
|
||||
preference :shopfront_product_sorting_method, :string, default: "by_category"
|
||||
|
||||
# Allow hubs to restrict visible variants to only those in their inventory
|
||||
preference :product_selection_from_inventory_only, :boolean, default: false
|
||||
|
||||
@@ -7,8 +7,9 @@ module Api
|
||||
:payment_method_ids, :shipping_method_ids, :producer_profile_only,
|
||||
:long_description, :preferred_product_selection_from_inventory_only,
|
||||
:preferred_shopfront_message, :preferred_shopfront_closed_message,
|
||||
:preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order,
|
||||
:preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups,
|
||||
:preferred_shopfront_taxon_order, :preferred_shopfront_producer_order,
|
||||
:preferred_shopfront_order_cycle_order, :preferred_show_customer_names_to_suppliers,
|
||||
:preferred_shopfront_product_sorting_method, :owner, :contact, :users, :tag_groups,
|
||||
:default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes,
|
||||
:logo, :promo_image, :terms_and_conditions,
|
||||
:terms_and_conditions_file_name, :terms_and_conditions_updated_at
|
||||
|
||||
@@ -30,7 +30,8 @@ module PermittedAttributes
|
||||
:abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text,
|
||||
:preferred_product_selection_from_inventory_only, :preferred_shopfront_message,
|
||||
:preferred_shopfront_closed_message, :preferred_shopfront_taxon_order,
|
||||
:preferred_shopfront_order_cycle_order, :preferred_show_customer_names_to_suppliers
|
||||
:preferred_shopfront_producer_order, :preferred_shopfront_order_cycle_order,
|
||||
:preferred_show_customer_names_to_suppliers, :preferred_shopfront_product_sorting_method,
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,7 +60,11 @@ class ProductsRenderer
|
||||
end
|
||||
|
||||
def taxon_order
|
||||
if distributor.preferred_shopfront_taxon_order.present?
|
||||
if distributor.preferred_shopfront_product_sorting_method == "by_producer"
|
||||
# todo: replace with preferred_shopfront_producer_order like for category
|
||||
# todo: order per producer or category alphabetically if no perferred order is present?
|
||||
"spree_products.supplier_id, spree_products.id"
|
||||
elsif distributor.preferred_shopfront_product_sorting_method == "by_category" && distributor.preferred_shopfront_taxon_order.present?
|
||||
distributor
|
||||
.preferred_shopfront_taxon_order
|
||||
.split(",").map { |id| "spree_products.primary_taxon_id=#{id} DESC" }
|
||||
|
||||
@@ -12,13 +12,29 @@
|
||||
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular textangular-strip', 'ta-paste' => "stripFormatting($html)", "textangular-links-target-blank" => true,
|
||||
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
|
||||
'placeholder' => t('.shopfront_closed_message_placeholder')}
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label "enterprise_preferred_shopfront_taxon_order", t('.shopfront_category_ordering')
|
||||
.text-normal
|
||||
= t('.display_ordering_in_shopfront')
|
||||
%br
|
||||
= t('.shopfront_category_ordering_note')
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= radio_button :enterprise, :preferred_shopfront_product_sorting_method, :by_category, { 'ng-model' => 'Enterprise.preferred_shopfront_product_sorting_method' }
|
||||
= label :enterprise, :preferred_shopfront_product_sorting_method_by_category, t('.shopfront_sort_by_category')
|
||||
.eight.columns.omega
|
||||
%textarea.fullwidth{ id: 'enterprise_preferred_shopfront_taxon_order', name: 'enterprise[preferred_shopfront_taxon_order]', rows: 6, 'ng-model' => 'Enterprise.preferred_shopfront_taxon_order', 'ofn-taxon-autocomplete' => '', 'multiple-selection' => 'true', placeholder: 'Category' }
|
||||
%textarea.fullwidth{ id: 'enterprise_preferred_shopfront_taxon_order', name: 'enterprise[preferred_shopfront_taxon_order]', rows: 6,
|
||||
'ofn-taxon-autocomplete' => '', 'multiple-selection' => 'true', placeholder: 'Category',
|
||||
ng: { model: 'Enterprise.preferred_shopfront_taxon_order', readonly: "Enterprise.preferred_shopfront_product_sorting_method != 'by_category'" }}
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= radio_button :enterprise, :preferred_shopfront_product_sorting_method, :by_producer, { 'ng-model' => 'Enterprise.preferred_shopfront_product_sorting_method' }
|
||||
= label :enterprise, :preferred_shopfront_product_sorting_method_by_producer, t('.shopfront_sort_by_producer')
|
||||
-# todo: create directive to support producer selector below
|
||||
-# .eight.columns.omega
|
||||
-# %textarea.fullwidth{ id: 'enterprise_preferred_shopfront_producer_order', name: 'enterprise[preferred_shopfront_producer_order]', rows: 6,
|
||||
-# 'ofn-producer-autocomplete' => '', 'multiple-selection' => 'true', placeholder: 'Producer',
|
||||
-# ng: { model: 'Enterprise.preferred_shopfront_producer_order', readonly: "Enterprise.preferred_shopfront_product_sorting_method != 'by_producer'" }}
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
|
||||
@@ -875,6 +875,9 @@ en:
|
||||
shopfront_category_ordering_note: "(top to bottom)"
|
||||
open_date: "Open Date"
|
||||
close_date: "Close Date"
|
||||
display_ordering_in_shopfront: "Display ordering in shopfront:"
|
||||
shopfront_sort_by_category: "By category"
|
||||
shopfront_sort_by_producer: "By producer"
|
||||
social:
|
||||
twitter_placeholder: "eg. @the_prof"
|
||||
instagram_placeholder: "eg. the_prof"
|
||||
|
||||
@@ -187,6 +187,8 @@ describe Enterprise do
|
||||
expect(enterprise).to be_invalid
|
||||
end
|
||||
end
|
||||
|
||||
# todo: describe "preferred_shopfront_producer_order"
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
|
||||
@@ -12,10 +12,12 @@ describe ProductsRenderer do
|
||||
describe "sorting" do
|
||||
let(:t1) { create(:taxon) }
|
||||
let(:t2) { create(:taxon) }
|
||||
let!(:p1) { create(:product, name: "abc", primary_taxon_id: t2.id) }
|
||||
let!(:p2) { create(:product, name: "def", primary_taxon_id: t1.id) }
|
||||
let!(:p3) { create(:product, name: "ghi", primary_taxon_id: t2.id) }
|
||||
let!(:p4) { create(:product, name: "jkl", primary_taxon_id: t1.id) }
|
||||
let(:s1) { create(:supplier_enterprise) }
|
||||
let(:s2) { create(:supplier_enterprise) }
|
||||
let!(:p1) { create(:product, name: "abc", primary_taxon_id: t2.id, supplier_id: s1.id) }
|
||||
let!(:p2) { create(:product, name: "def", primary_taxon_id: t1.id, supplier_id: s2.id) }
|
||||
let!(:p3) { create(:product, name: "ghi", primary_taxon_id: t2.id, supplier_id: s1.id) }
|
||||
let!(:p4) { create(:product, name: "jkl", primary_taxon_id: t1.id, supplier_id: s2.id) }
|
||||
|
||||
before do
|
||||
exchange.variants << p1.variants.first
|
||||
@@ -30,6 +32,20 @@ describe ProductsRenderer do
|
||||
expect(products).to eq([p2, p4, p1, p3])
|
||||
end
|
||||
|
||||
it "sorts products by producer id" do # todo: remove this temporary test
|
||||
allow(distributor).to receive(:preferred_shopfront_product_sorting_method) { "by_producer" }
|
||||
puts(distributor.preferred_shopfront_product_sorting_method)
|
||||
products = products_renderer.send(:products)
|
||||
expect(products).to eq([p1, p3, p2, p4])
|
||||
end
|
||||
|
||||
# todo: it "sorts products by the distributor's preferred producer list" do
|
||||
# allow(distributor).to receive(:preferred_shopfront_product_sorting_method) { "by_producer" }
|
||||
# allow(distributor).to receive(:preferred_shopfront_producer_order) { "#{s2.id},#{s1.id}" }
|
||||
# products = products_renderer.send(:products)
|
||||
# expect(products).to eq([p2, p4, p1, p3])
|
||||
# end
|
||||
|
||||
it "alphabetizes products by name when taxon list is not set" do
|
||||
allow(distributor).to receive(:preferred_shopfront_taxon_order) { "" }
|
||||
products = products_renderer.send(:products)
|
||||
|
||||
Reference in New Issue
Block a user