1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(bug) fix add to cart button can't apply a quantity min

This commit is contained in:
Du Peng 2022-09-13 16:36:44 +02:00
parent 7673c1f814
commit b76c7889ac
5 changed files with 7 additions and 1 deletions

View File

@ -151,7 +151,7 @@ const StoreCart: React.FC<StoreCartProps> = ({ onSuccess, onError, currentUser,
<span>/ {t('app.public.store_cart.unit')}</span>
</div>
<select value={item.quantity} onChange={changeProductQuantity(item)}>
{Array.from({ length: 100 }, (_, i) => i + 1).map(v => (
{Array.from({ length: 100 }, (_, i) => i + item.quantity_min).map(v => (
<option key={v} value={v}>{v}</option>
))}
</select>

View File

@ -33,6 +33,7 @@ export interface Order {
orderable_name: string,
orderable_main_image_url?: string,
quantity: number,
quantity_min: number,
amount: number,
is_offered: boolean
}>,

View File

@ -7,6 +7,8 @@ class Cart::AddItemService
raise Cart::InactiveProductError unless orderable.is_active
quantity = orderable.quantity_min > quantity.to_i ? orderable.quantity_min : quantity.to_i
raise Cart::OutStockError if quantity > orderable.stock['external']
item = order.order_items.find_by(orderable: orderable)

View File

@ -5,6 +5,8 @@ class Cart::SetQuantityService
def call(order, orderable, quantity = nil)
return order if quantity.to_i.zero?
quantity = orderable.quantity_min > quantity.to_i ? orderable.quantity_min : quantity.to_i
raise Cart::OutStockError if quantity.to_i > orderable.stock['external']
item = order.order_items.find_by(orderable: orderable)

View File

@ -27,6 +27,7 @@ json.order_items_attributes order.order_items.order(created_at: :asc) do |item|
json.orderable_name item.orderable.name
json.orderable_main_image_url item.orderable.main_image&.attachment_url
json.quantity item.quantity
json.quantity_min item.orderable.quantity_min
json.amount item.amount / 100.0
json.is_offered item.is_offered
end