Kaynağa Gözat

feat(admin-ui): Correctly display cancelled Fulfillments

Relates to #565
Michael Bromley 5 yıl önce
ebeveyn
işleme
7efe8007db

+ 5 - 0
packages/admin-ui/src/lib/core/src/common/generated-types.ts

@@ -5152,6 +5152,10 @@ export type OrderFragment = (
 export type FulfillmentFragment = (
   { __typename?: 'Fulfillment' }
   & Pick<Fulfillment, 'id' | 'state' | 'nextStates' | 'createdAt' | 'updatedAt' | 'method' | 'trackingCode'>
+  & { orderItems: Array<(
+    { __typename?: 'OrderItem' }
+    & Pick<OrderItem, 'id'>
+  )> }
 );
 
 export type OrderLineFragment = (
@@ -7691,6 +7695,7 @@ export namespace Order {
 
 export namespace Fulfillment {
   export type Fragment = FulfillmentFragment;
+  export type OrderItems = NonNullable<(NonNullable<FulfillmentFragment['orderItems']>)[number]>;
 }
 
 export namespace OrderLine {

+ 3 - 0
packages/admin-ui/src/lib/core/src/data/definitions/order-definitions.ts

@@ -64,6 +64,9 @@ export const FULFILLMENT_FRAGMENT = gql`
         createdAt
         updatedAt
         method
+        orderItems {
+            id
+        }
         trackingCode
     }
 `;

+ 2 - 1
packages/admin-ui/src/lib/order/src/components/fulfillment-detail/fulfillment-detail.component.ts

@@ -17,9 +17,10 @@ export class FulfillmentDetailComponent {
 
     get items(): Array<{ name: string; quantity: number }> {
         const itemMap = new Map<string, number>();
+        const fulfillmentItemIds = this.fulfillment?.orderItems.map(i => i.id);
         for (const line of this.order.lines) {
             for (const item of line.items) {
-                if (item.fulfillment && item.fulfillment.id === this.fulfillmentId) {
+                if (fulfillmentItemIds?.includes(item.id)) {
                     const count = itemMap.get(line.productVariant.name);
                     if (count != null) {
                         itemMap.set(line.productVariant.name, count + 1);