mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
Add search_variants_as parameter to variant search functionality
This commit is contained in:
@@ -5,6 +5,7 @@ angular.module("admin.orders").controller "orderCtrl", ($scope, shops, orderCycl
|
||||
|
||||
$scope.distributor_id = parseInt($attrs.ofnDistributorId)
|
||||
$scope.order_cycle_id = parseInt($attrs.ofnOrderCycleId)
|
||||
$scope.search_variants_as = $attrs.ofnSearchVariantsAs
|
||||
|
||||
$scope.validOrderCycle = (oc) ->
|
||||
$scope.orderCycleHasDistributor oc, parseInt($scope.distributor_id)
|
||||
|
||||
@@ -26,6 +26,7 @@ angular.module("admin.utils").directive "variantAutocomplete", ($timeout) ->
|
||||
order_cycle_id: scope.order_cycle_id
|
||||
eligible_for_subscriptions: scope.eligible_for_subscriptions
|
||||
include_out_of_stock: scope.include_out_of_stock
|
||||
search_variants_as: scope.search_variants_as
|
||||
results: (data, page) ->
|
||||
window.variants = data # this is how spree auto complete JS code picks up variants
|
||||
results: data
|
||||
|
||||
@@ -117,7 +117,7 @@ module Spree
|
||||
def variant_search_params
|
||||
params.permit(
|
||||
:q, :distributor_id, :order_cycle_id, :schedule_id, :eligible_for_subscriptions,
|
||||
:include_out_of_stock
|
||||
:include_out_of_stock, :search_variants_as,
|
||||
).to_h.with_indifferent_access
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ module OpenFoodNetwork
|
||||
scope_to_schedule if params[:schedule_id]
|
||||
scope_to_order_cycle if params[:order_cycle_id]
|
||||
scope_to_distributor if params[:distributor_id]
|
||||
scope_to_supplier if spree_current_user.can_manage_line_items_in_orders_only?
|
||||
scope_to_supplier if params[:search_variants_as] == 'supplier'
|
||||
|
||||
@variants
|
||||
end
|
||||
|
||||
@@ -137,6 +137,13 @@ RSpec.describe Spree::Admin::VariantsController do
|
||||
expect(variant).to have_received(:destroy)
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
it "filters by distributor and supplier1 products" do
|
||||
spree_get :search, q: 'Prod', distributor_id: d.id.to_s, search_variants_as: 'supplier'
|
||||
expect(assigns(:variants)).to eq([v1])
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows a success flash message' do
|
||||
spree_delete :destroy, id: variant.id, product_id: variant.product.id,
|
||||
format: 'html'
|
||||
|
||||
@@ -185,7 +185,7 @@ RSpec.describe OpenFoodNetwork::ScopeVariantsForSearch do
|
||||
end
|
||||
|
||||
context "when search is done by the producer allowing to edit orders" do
|
||||
let(:params) { { q: "product" } }
|
||||
let(:params) { { q: "product", search_variants_as: 'supplier' } }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let!(:spree_current_user) {
|
||||
instance_double('Spree::User', enterprises: Enterprise.where(id: producer.id),
|
||||
|
||||
Reference in New Issue
Block a user