Jelajahi Sumber

feat(mcp-shoprenter): add orderTotals breakdown to order response

Shows subtotal, tax, shipping, and total in plain text format.
Skips loyalty points from the output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh 4 bulan lalu
induk
melakukan
f5752544ef
1 mengubah file dengan 15 tambahan dan 1 penghapusan
  1. 15 1
      supabase/functions/mcp-shoprenter/index.ts

+ 15 - 1
supabase/functions/mcp-shoprenter/index.ts

@@ -375,7 +375,21 @@ function formatOrderAsPlainText(o: any): string {
   text += `\nStatus: ${statusText}`;
   text += `\nStatus: ${statusText}`;
 
 
   const currency = o.currency?.code || o.currency || '';
   const currency = o.currency?.code || o.currency || '';
-  text += `\nTotal: ${o.total || '0'}${currency ? ' ' + currency : ''}`;
+
+  // Add order totals breakdown if available
+  const orderTotals = o.orderTotals || [];
+  if (orderTotals.length > 0) {
+    text += '\nOrder Totals:';
+    for (const total of orderTotals) {
+      // Skip loyalty points and other non-monetary totals
+      if (total.type === 'LOYALTYPOINTS_TO_GET') continue;
+      const name = total.name?.replace(/:$/, '') || total.type || 'Unknown';
+      const valueText = total.valueText || `${total.value}${currency ? ' ' + currency : ''}`;
+      text += `\n    - ${name}: ${valueText}`;
+    }
+  } else {
+    text += `\nTotal: ${o.total || '0'}${currency ? ' ' + currency : ''}`;
+  }
 
 
   const items = o.orderProducts || o.items || [];
   const items = o.orderProducts || o.items || [];
   if (items.length > 0) {
   if (items.length > 0) {