mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Show property badges on shops
This commit is contained in:
@@ -22,6 +22,7 @@ end
|
||||
class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :orders_close_at, :active
|
||||
has_many :supplied_properties, serializer: Api::PropertySerializer
|
||||
has_many :distributed_properties, serializer: Api::PropertySerializer
|
||||
|
||||
def orders_close_at
|
||||
options[:data].earliest_closing_times[object.id]
|
||||
@@ -38,6 +39,15 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties
|
||||
end
|
||||
|
||||
def distributed_properties
|
||||
# This results in 3 queries per enterprise
|
||||
product_properties = Spree::Property.sold_by(object)
|
||||
ids = ProducerProperty.sold_by(object).pluck(:property_id)
|
||||
producer_properties = Spree::Property.where(id: ids)
|
||||
|
||||
OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties
|
||||
end
|
||||
end
|
||||
|
||||
class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
%label
|
||||
= t :hubs_buy
|
||||
.trans-sentence
|
||||
%span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"}
|
||||
%render-svg{path: "{{taxon.icon}}"}
|
||||
%span{"ng-bind" => "::taxon.name"}
|
||||
%div
|
||||
%span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"}
|
||||
%render-svg{path: "{{taxon.icon}}"}
|
||||
%span{"ng-bind" => "::taxon.name"}
|
||||
%div
|
||||
%span.fat-properties{"ng-repeat" => "property in hub.distributed_properties"}
|
||||
%span{"ng-bind" => "property.presentation"}
|
||||
%div.show-for-medium-up{"ng-if" => "::hub.taxons.length==0"}
|
||||
|
||||
.columns.small-12.medium-3.large-2.fat
|
||||
|
||||
@@ -56,12 +56,36 @@ feature 'Shops', js: true do
|
||||
expect(page).to have_current_path enterprise_shop_path(distributor)
|
||||
end
|
||||
|
||||
describe "property badges" do
|
||||
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
|
||||
let(:product) { create(:simple_product, supplier: producer) }
|
||||
|
||||
before do
|
||||
product.set_property 'Local', 'XYZ 123'
|
||||
end
|
||||
|
||||
it "shows property badges" do
|
||||
# Given a shop with a product with a property
|
||||
# And the product's producer has a producer property
|
||||
|
||||
# When I go to the shops path
|
||||
visit shops_path
|
||||
|
||||
# And I open the shop
|
||||
expand_active_table_node distributor.name
|
||||
|
||||
# Then I should see both properties
|
||||
expect(page).to have_content 'Local' # Product property
|
||||
expect(page).to have_content 'Organic' # Producer property
|
||||
end
|
||||
end
|
||||
|
||||
describe "hub producer modal" do
|
||||
let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) }
|
||||
let!(:taxon) { create(:taxon, name: 'Fruit') }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
|
||||
|
||||
it "should show hub producer modals" do
|
||||
it "shows hub producer modals" do
|
||||
expand_active_table_node distributor.name
|
||||
expect(page).to have_content producer.name
|
||||
open_enterprise_modal producer
|
||||
|
||||
Reference in New Issue
Block a user