u
This commit is contained in:
@@ -62,6 +62,19 @@ export async function importOrders({
|
||||
defaultCustomerGroupId = groups[0]?.id || null;
|
||||
} catch {}
|
||||
|
||||
let defaultWarehouseId = null;
|
||||
try {
|
||||
const warehouses = await store.warehouse.list(googleAuthId);
|
||||
if (warehouses && warehouses.length > 0) {
|
||||
defaultWarehouseId = warehouses[0].id;
|
||||
} else {
|
||||
const wh = await store.warehouse.create(googleAuthId, { name: 'Standardlager' });
|
||||
defaultWarehouseId = wh.id;
|
||||
}
|
||||
} catch (err) {
|
||||
log.warn('Could not ensure warehouse:', err.message);
|
||||
}
|
||||
|
||||
const entityMap = new Map();
|
||||
try {
|
||||
const entities = await store.entity.list(googleAuthId);
|
||||
@@ -220,19 +233,37 @@ export async function importOrders({
|
||||
|
||||
// Handle Delivery / Shipping
|
||||
const shippingType = cleanValue(m.shippingType);
|
||||
if (shippingType) {
|
||||
const isShipped = String(m.shipped ?? '').trim() === '1';
|
||||
const shippingState = isShipped ? 'shipped' : 'open';
|
||||
const isShipped = String(m.shipped ?? '').trim() === '1';
|
||||
|
||||
try {
|
||||
await store.shipping.create(googleAuthId, {
|
||||
manifestId: createdOrder.id,
|
||||
type: shippingType,
|
||||
state: shippingState,
|
||||
});
|
||||
shippingsImported++;
|
||||
} catch (err) {
|
||||
log.warn(`Failed to create shipping for order ${orderNumber}:`, err.message);
|
||||
if (isShipped || shippingType) {
|
||||
const shippableLines = lines
|
||||
.filter((l) => l.sku)
|
||||
.map((l) => ({ sku: l.sku, amount: l.amount }));
|
||||
|
||||
if (shippableLines.length > 0) {
|
||||
try {
|
||||
const shipment = await store.shipment.create(googleAuthId, {
|
||||
orderId: createdOrder.id,
|
||||
date: validDate,
|
||||
lines: shippableLines,
|
||||
});
|
||||
|
||||
const trackingCode = cleanValue(m.trackingCode ?? m.tracking_code ?? m.cTracking);
|
||||
const carrier = cleanValue(m.carrier ?? m.cCarrier);
|
||||
const shippingState = isShipped ? 'shipped' : 'draft';
|
||||
|
||||
await store.shipping.create(googleAuthId, {
|
||||
manifestId: shipment.id,
|
||||
type: shippingType || 'standard',
|
||||
state: shippingState,
|
||||
trackingCode: trackingCode || undefined,
|
||||
carrier: carrier || undefined,
|
||||
warehouseId: defaultWarehouseId || undefined,
|
||||
});
|
||||
shippingsImported++;
|
||||
} catch (err) {
|
||||
log.warn(`Failed to create shipment/shipping for order ${orderNumber}:`, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user