@base44/app-plugin-commerce 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,20 +91,31 @@ export function orderTotalsLines(order, { formatMoney, labels = {} } = {}) {
91
91
 
92
92
  /**
93
93
  * An order's line items in the same shape as decorated cart lines, so one
94
- * component renders the bag, the checkout summary and the confirmation.
94
+ * component renders the bag, the checkout summary and the confirmation
95
+ * `image` is `{src, alt}|null` and `totalLabel` is pre-formatted, exactly as
96
+ * on `useCart().lines` (pass `formatMoney`; `useOrderReturn` does).
95
97
  *
96
98
  * @param {object} order
99
+ * @param {{formatMoney?: (n: number) => string}} [opts]
97
100
  * @returns {Array<{name: string, attributesLabel: string, quantity: number,
98
- * total: number, image: object|null, sku: string}>}
101
+ * total: number, totalLabel: string, image: {src: string, alt: string}|null,
102
+ * sku: string}>}
99
103
  */
100
- export function orderLines(order) {
101
- return (order?.line_items ?? []).map((it) => ({
102
- ...it,
103
- name: it.name ?? "",
104
- attributesLabel: attributesLabel(it.attributes ?? it.meta_data),
105
- quantity: num(it.quantity),
106
- total: num(it.total ?? it.subtotal),
107
- image: it.image ?? null,
108
- sku: it.sku ?? "",
109
- }));
104
+ export function orderLines(order, { formatMoney } = {}) {
105
+ return (order?.line_items ?? []).map((it) => {
106
+ const total = num(it.total ?? it.subtotal);
107
+ // An order item's image may be stored as a bare URL or an object — either
108
+ // way it leaves here as {src, alt}|null, the cart-line shape.
109
+ const src = typeof it.image === "string" ? it.image : it.image?.src;
110
+ return {
111
+ ...it,
112
+ name: it.name ?? "",
113
+ attributesLabel: attributesLabel(it.attributes ?? it.meta_data),
114
+ quantity: num(it.quantity),
115
+ total,
116
+ totalLabel: money(formatMoney, total),
117
+ image: src ? { src, alt: (typeof it.image === "object" ? it.image?.alt : "") || it.name || "" } : null,
118
+ sku: it.sku ?? "",
119
+ };
120
+ });
110
121
  }