feat(inventory): link online order reservations to database hold and sync numerical stock in RSS/Torob feeds
This commit is contained in:
1 parent
01de33ff2b
commit
d6a2136c70
3 files changed
+28
-8
No files matched your search
@@ -309,6 +309,7 @@ export class OrdersService {
|
||||
|
||||
const isOnline = createOrderDto.paymentMethod === 'online';
|
||||
const initialStatus = isOnline ? 'pending_payment' : 'processing';
|
||||
const reservationExpiry = new Date(Date.now() + 15 * 60 * 1000); // 15 minutes hold
|
||||
|
||||
const createdOrder = await this.prisma.$transaction(async (tx) => {
|
||||
const order = await tx.order.create({
|
||||
@@ -326,14 +327,22 @@ export class OrdersService {
|
||||
orderItems: {
|
||||
create: orderItemsData,
|
||||
},
|
||||
inventoryReservations: {
|
||||
create: orderItemsData.map((item) => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
expiresAt: reservationExpiry,
|
||||
status: isOnline ? 'ACTIVE' : 'CONSUMED',
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
orderItems: {
|
||||
include: { product: true },
|
||||
},
|
||||
inventoryReservations: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Deduct inventory immediately for non-online orders (card to card)
|
||||
if (!isOnline) {
|
||||
for (const item of createOrderDto.items) {
|
||||
|
||||
@@ -153,11 +153,14 @@ export async function GET(request: NextRequest) {
|
||||
: `${baseUrl}${proxied.startsWith('/') ? proxied : `/${proxied}`}`;
|
||||
}
|
||||
|
||||
const isInStock =
|
||||
product.stockStatus !== 'OUT_OF_STOCK' &&
|
||||
product.stockStatus !== 'out_of_stock' &&
|
||||
product.stockStatus !== 'DISCONTINUED' &&
|
||||
product.inStock !== false;
|
||||
const isOutOfStock =
|
||||
product.stockStatus === 'OUT_OF_STOCK' ||
|
||||
product.stockStatus === 'out_of_stock' ||
|
||||
product.stockStatus === 'DISCONTINUED' ||
|
||||
product.inStock === false ||
|
||||
(typeof product.stock === 'number' && product.stock <= 0);
|
||||
|
||||
const isInStock = !isOutOfStock;
|
||||
|
||||
const price = Number(product.priceValue || product.price || 0);
|
||||
const oldPrice = Number(product.oldPrice || product.priceValue || product.price || 0);
|
||||
|
||||
@@ -34,9 +34,17 @@ export async function GET() {
|
||||
imageLink = proxied.startsWith('http') ? proxied : `${baseUrl}${proxied.startsWith('/') ? proxied : `/${proxied}`}`;
|
||||
}
|
||||
|
||||
const isOutOfStock =
|
||||
product.stockStatus === 'OUT_OF_STOCK' ||
|
||||
product.stockStatus === 'DISCONTINUED' ||
|
||||
(typeof product.stock === 'number' && product.stock <= 0);
|
||||
|
||||
let availability = 'in_stock';
|
||||
if (product.stockStatus === 'OUT_OF_STOCK') availability = 'out_of_stock';
|
||||
if (product.stockStatus === 'PRE_ORDER') availability = 'preorder';
|
||||
if (isOutOfStock) {
|
||||
availability = 'out_of_stock';
|
||||
} else if (product.stockStatus === 'PRE_ORDER') {
|
||||
availability = 'preorder';
|
||||
}
|
||||
|
||||
const price = product.priceValue ? `${product.priceValue * 10} IRR` : '0 IRR';
|
||||
const gtinTag = product.barcode ? `<g:gtin>${product.barcode}</g:gtin>` : '';
|
||||
|
||||
Reference in new issue
Block a user