add ability search supplier products in orders

This commit is contained in:
Ahmed Ejaz
2025-02-16 01:51:13 +05:00
parent 19c5fec9a9
commit d9308799b0
2 changed files with 12 additions and 3 deletions

View File

@@ -64,7 +64,10 @@ module Spree
end
def search
scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(variant_search_params)
scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(
variant_search_params,
spree_current_user
)
@variants = scoper.search
render json: @variants, each_serializer: ::Api::Admin::VariantSerializer
end

View File

@@ -9,8 +9,9 @@ require 'open_food_network/scope_variant_to_hub'
module OpenFoodNetwork
class ScopeVariantsForSearch
def initialize(params)
def initialize(params, spree_current_user)
@params = params
@spree_current_user = spree_current_user
end
def search
@@ -20,13 +21,14 @@ 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?
@variants
end
private
attr_reader :params
attr_reader :params, :spree_current_user
def search_params
{ product_name_cont: params[:q], sku_cont: params[:q], product_sku_cont: params[:q] }
@@ -96,5 +98,9 @@ module OpenFoodNetwork
# Filtering could be a problem on scoped variants.
variants.each { |v| scoper.scope(v) }
end
def scope_to_supplier
@variants = @variants.where(supplier_id: spree_current_user.enterprises.ids)
end
end
end