mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
DistributionChangeValidator checks if an order can change to a specified new distributION
This commit is contained in:
@@ -4,11 +4,19 @@ class DistributionChangeValidator
|
||||
@order = order
|
||||
end
|
||||
|
||||
def can_change_to_distributor? distributor
|
||||
def can_change_to_distributor?(distributor)
|
||||
# Distributor may not be changed once an item has been added to the cart/order, unless all items are available from the specified distributor
|
||||
@order.line_items.empty? || all_available_distributors.include?(distributor)
|
||||
end
|
||||
|
||||
def can_change_to_distribution?(distributor, order_cycle)
|
||||
(@order.line_item_variants - variants_available_for_distribution(distributor, order_cycle)).empty?
|
||||
end
|
||||
|
||||
def variants_available_for_distribution(distributor, order_cycle)
|
||||
distributor.distributed_variants + order_cycle.distributed_variants_by(distributor)
|
||||
end
|
||||
|
||||
def distributor_available_for?(product)
|
||||
@order.nil? || available_distributors_for(product).present?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user