DistributionChangeValidator checks if an order can change to a specified new distributION

This commit is contained in:
Rohan Mitchell
2013-06-17 15:00:19 +10:00
parent 27b5dc071a
commit be29974dd8
2 changed files with 50 additions and 3 deletions

View File

@@ -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