fullcart
Version:
Add stripe checkout to any website
16 lines (13 loc) • 550 B
text/typescript
import type { Customer } from '../schemas/customerSchema'
import type { Product } from '../schemas/productSchema'
import { customer } from '../stores/customer'
import { setQuantity } from './setQuantity'
export const updateQuantity = (
productId: Product['id'],
quantity: Customer['lines'][number]['quantity'],
) => {
const lines = customer.get().lines
const index = lines.findIndex((item) => item.productId === productId)
if (index < 0) setQuantity(productId, quantity)
else setQuantity(productId, lines[index].quantity += quantity)
}