mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rename service and methods to remove use of "shop" term
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Returns a (paginatable) AR object for the products or variants in stock for a given shop and OC.
|
||||
# The stock-checking includes on_demand and stock level overrides from variant_overrides.
|
||||
|
||||
class ShopProductsService
|
||||
class OrderCycleDistributedProducts
|
||||
def initialize(distributor, order_cycle)
|
||||
@distributor = distributor
|
||||
@order_cycle = order_cycle
|
||||
@@ -10,10 +10,10 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def products_json
|
||||
if shop_products
|
||||
if products
|
||||
enterprise_fee_calculator = EnterpriseFeeCalculator.new @distributor, @order_cycle
|
||||
|
||||
ActiveModel::ArraySerializer.new(shop_products,
|
||||
ActiveModel::ArraySerializer.new(products,
|
||||
each_serializer: Api::ProductSerializer,
|
||||
current_order_cycle: @order_cycle,
|
||||
current_distributor: @distributor,
|
||||
@@ -27,20 +27,20 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def shop_products
|
||||
def products
|
||||
return unless @order_cycle
|
||||
|
||||
@shop_products ||= begin
|
||||
@products ||= begin
|
||||
scoper = ScopeProductToHub.new(@distributor)
|
||||
|
||||
shop_products_service.products_relation.
|
||||
distributed_products.products_relation.
|
||||
order(taxon_order).
|
||||
each { |product| scoper.scope(product) }
|
||||
end
|
||||
end
|
||||
|
||||
def shop_products_service
|
||||
ShopProductsService.new(@distributor, @order_cycle)
|
||||
def distributed_products
|
||||
OrderCycleDistributedProducts.new(@distributor, @order_cycle)
|
||||
end
|
||||
|
||||
def taxon_order
|
||||
@@ -58,9 +58,9 @@ module OpenFoodNetwork
|
||||
@variants_for_shop ||= begin
|
||||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(@distributor)
|
||||
|
||||
shop_products_service.variants_relation.
|
||||
distributed_products.variants_relation.
|
||||
includes(:default_price, :stock_locations, :product).
|
||||
where(product_id: shop_products).
|
||||
where(product_id: products).
|
||||
each { |v| scoper.scope(v) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,13 +25,13 @@ module OpenFoodNetwork
|
||||
|
||||
it "sorts products by the distributor's preferred taxon list" do
|
||||
allow(distributor).to receive(:preferred_shopfront_taxon_order) { "#{t1.id},#{t2.id}" }
|
||||
products = pr.send(:shop_products)
|
||||
products = pr.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 = pr.send(:shop_products)
|
||||
products = pr.send(:products)
|
||||
expect(products).to eq([p1, p2, p3, p4])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ShopProductsService do
|
||||
describe OrderCycleDistributedProducts do
|
||||
describe "#products_relation" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:product) { create(:product) }
|
||||
Reference in New Issue
Block a user