Add shippedby to event feed

This commit is contained in:
2025-01-09 11:10:49 -05:00
parent 254a9a6511
commit 225e63a985
3 changed files with 78 additions and 135 deletions

View File

@@ -1339,58 +1339,62 @@ export class EventsService {
event.attributes?.metric_id;
// Extract properties from all possible locations
const rawProps = {
...(event.attributes?.event_properties || {}),
...(event.attributes?.properties || {}),
...(event.attributes?.profile || {}),
value: event.attributes?.value,
datetime: event.attributes?.datetime
};
const rawProps = event.attributes?.event_properties || {};
// Only log for shipped orders and only show relevant fields
if (event.relationships?.metric?.data?.id === METRIC_IDS.SHIPPED_ORDER) {
console.log('[EventsService] Shipped Order:', {
orderId: rawProps.OrderId,
shippedBy: rawProps.ShippedBy,
datetime: event.attributes?.datetime
});
}
// Normalize shipping data
const shippingData = {
name: rawProps.ShippingName || rawProps.shipping_name || rawProps.shipping?.name,
street1: rawProps.ShippingStreet1 || rawProps.shipping_street1 || rawProps.shipping?.street1,
street2: rawProps.ShippingStreet2 || rawProps.shipping_street2 || rawProps.shipping?.street2,
city: rawProps.ShippingCity || rawProps.shipping_city || rawProps.shipping?.city,
state: rawProps.ShippingState || rawProps.shipping_state || rawProps.shipping?.state,
zip: rawProps.ShippingZip || rawProps.shipping_zip || rawProps.shipping?.zip,
country: rawProps.ShippingCountry || rawProps.shipping_country || rawProps.shipping?.country,
method: rawProps.ShipMethod || rawProps.shipping_method || rawProps.shipping?.method,
tracking: rawProps.TrackingNumber || rawProps.tracking_number
ShippingName: rawProps.ShippingName,
ShippingStreet1: rawProps.ShippingStreet1,
ShippingStreet2: rawProps.ShippingStreet2,
ShippingCity: rawProps.ShippingCity,
ShippingState: rawProps.ShippingState,
ShippingZip: rawProps.ShippingZip,
ShippingCountry: rawProps.ShippingCountry,
ShipMethod: rawProps.ShipMethod,
TrackingNumber: rawProps.TrackingNumber,
ShippedBy: rawProps.ShippedBy
};
// Normalize payment data
const paymentData = {
method: rawProps.PaymentMethod || rawProps.payment_method || rawProps.payment?.method,
name: rawProps.PaymentName || rawProps.payment_name || rawProps.payment?.name,
amount: Number(rawProps.PaymentAmount || rawProps.payment_amount || rawProps.payment?.amount || 0)
method: rawProps.PaymentMethod,
name: rawProps.PaymentName,
amount: Number(rawProps.PaymentAmount || 0)
};
// Normalize order flags
const orderFlags = {
type: rawProps.OrderType || rawProps.order_type || 'standard',
hasPreorder: Boolean(rawProps.HasPreorder || rawProps.has_preorder || rawProps.preorder),
localPickup: Boolean(rawProps.LocalPickup || rawProps.local_pickup || rawProps.pickup),
isOnHold: Boolean(rawProps.IsOnHold || rawProps.is_on_hold || rawProps.on_hold),
hasDigiItem: Boolean(rawProps.HasDigiItem || rawProps.has_digital_item || rawProps.digital_item),
hasNotions: Boolean(rawProps.HasNotions || rawProps.has_notions || rawProps.notions),
hasDigitalGC: Boolean(rawProps.HasDigitalGC || rawProps.has_digital_gc || rawProps.gift_card),
stillOwes: Boolean(rawProps.StillOwes || rawProps.still_owes || rawProps.balance_due)
type: rawProps.OrderType || 'standard',
hasPreorder: Boolean(rawProps.HasPreorder),
localPickup: Boolean(rawProps.LocalPickup),
isOnHold: Boolean(rawProps.IsOnHold),
hasDigiItem: Boolean(rawProps.HasDigiItem),
hasNotions: Boolean(rawProps.HasNotions),
hasDigitalGC: Boolean(rawProps.HasDigitalGC),
stillOwes: Boolean(rawProps.StillOwes)
};
// Normalize refund/cancel data
const refundData = {
reason: rawProps.CancelReason || rawProps.cancel_reason || rawProps.reason,
message: rawProps.CancelMessage || rawProps.cancel_message || rawProps.message,
orderMessage: rawProps.OrderMessage || rawProps.order_message || rawProps.note
reason: rawProps.CancelReason,
message: rawProps.CancelMessage,
orderMessage: rawProps.OrderMessage
};
// Transform items
const items = this._transformItems(rawProps.Items || rawProps.items || rawProps.line_items || []);
const items = this._transformItems(rawProps.Items || []);
// Calculate totals
const totalAmount = Number(rawProps.TotalAmount || rawProps.PaymentAmount || rawProps.total_amount || rawProps.value || 0);
const totalAmount = Number(rawProps.TotalAmount || rawProps.PaymentAmount || rawProps.value || 0);
const itemCount = items.reduce((sum, item) => sum + Number(item.Quantity || item.QuantityOrdered || 1), 0);
const transformed = {
@@ -1408,29 +1412,10 @@ export class EventsService {
},
relationships: event.relationships,
event_properties: {
// Basic properties
EmailAddress: rawProps.EmailAddress || rawProps.email,
FirstName: rawProps.FirstName || rawProps.first_name,
LastName: rawProps.LastName || rawProps.last_name,
OrderId: rawProps.OrderId || rawProps.FromOrder || rawProps.order_id,
...rawProps, // Include all original properties
Items: items, // Override with transformed items
TotalAmount: totalAmount,
ItemCount: itemCount,
Items: items,
// Shipping information
...shippingData,
// Payment information
...paymentData,
// Order flags
...orderFlags,
// Refund/cancel information
...refundData,
// Original properties (for backward compatibility)
...rawProps
ItemCount: itemCount
}
};