1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

(feat) check order's item amount and quantity min before checkout

This commit is contained in:
Du Peng 2022-09-19 16:51:50 +02:00
parent e2b6267924
commit c424e80f8b
4 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
# Raised when the item's amount != product's amount
class Cart::ItemAmountError < StandardError
end

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
# Raised when the item's quantity < product's quantity min
class Cart::QuantityMinError < StandardError
end

View File

@ -11,6 +11,10 @@ class Checkout::PaymentService
raise Cart::OutStockError unless Orders::OrderService.new.in_stock?(order, 'external')
raise Cart::QuantityMinError unless Orders::OrderService.new.greater_than_quantity_min?(order)
raise Cart::ItemAmountError unless Orders::OrderService.new.item_amount_not_equal?(order)
CouponService.new.validate(coupon_code, order.statistic_profile.user.id)
amount = debit_amount(order)

View File

@ -58,6 +58,20 @@ class Orders::OrderService
true
end
def greater_than_quantity_min?(order)
order.order_items.each do |item|
return false if item.quantity < item.orderable.quantity_min
end
true
end
def item_amount_not_equal?(order)
order.order_items.each do |item|
return false if item.amount != item.orderable.amount
end
true
end
def all_products_is_active?(order)
order.order_items.each do |item|
return false unless item.orderable.is_active