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:
parent
e2b6267924
commit
c424e80f8b
5
app/exceptions/cart/item_amount_error.rb
Normal file
5
app/exceptions/cart/item_amount_error.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Raised when the item's amount != product's amount
|
||||
class Cart::ItemAmountError < StandardError
|
||||
end
|
5
app/exceptions/cart/quantity_min_error.rb
Normal file
5
app/exceptions/cart/quantity_min_error.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Raised when the item's quantity < product's quantity min
|
||||
class Cart::QuantityMinError < StandardError
|
||||
end
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user