diff --git a/packages/core/graphql/src/lib/documents/fragments/order.gql b/packages/core/graphql/src/lib/documents/fragments/order.gql index 7ce57a33..9006a88d 100644 --- a/packages/core/graphql/src/lib/documents/fragments/order.gql +++ b/packages/core/graphql/src/lib/documents/fragments/order.gql @@ -2,10 +2,14 @@ fragment OrderFragment on IoRestorecommerceOrderOrder { id customerOrderNr notificationEmail + shopId orderState items { id quantity + productId + variantId + parentItemId product { ...ProductFragment } @@ -62,6 +66,40 @@ fragment OrderFragment on IoRestorecommerceOrderOrder { } } } + billingAddress { + comments + contact { + name + email + phone + } + address { + id + street + buildingNumber + locality + region + businessAddress { + name + } + addressAddition { + field1 + field2 + } + country { + id + name + countryCode + } + postcode + residentialAddress { + title + givenName + midName + familyName + } + } + } totalAmounts { currency { name diff --git a/packages/core/graphql/src/lib/generated/generated.ts b/packages/core/graphql/src/lib/generated/generated.ts index e927d6fc..12217311 100644 --- a/packages/core/graphql/src/lib/generated/generated.ts +++ b/packages/core/graphql/src/lib/generated/generated.ts @@ -5969,11 +5969,15 @@ export type OrderFragmentFragment = { id?: string | null; customerOrderNr?: string | null; notificationEmail?: string | null; + shopId?: string | null; orderState?: IoRestorecommerceOrderOrderState | null; items?: Array<{ __typename?: 'IoRestorecommerceOrderItem'; id?: string | null; quantity?: number | null; + productId?: string | null; + variantId?: string | null; + parentItemId?: string | null; product?: { __typename?: 'IoRestorecommerceProductProduct'; id?: string | null; @@ -6403,6 +6407,47 @@ export type OrderFragmentFragment = { } | null; } | null; } | null; + billingAddress?: { + __typename?: 'IoRestorecommerceAddressBillingAddress'; + comments?: string | null; + contact?: { + __typename?: 'IoRestorecommerceAddressContact'; + name?: string | null; + email?: string | null; + phone?: string | null; + } | null; + address?: { + __typename?: 'IoRestorecommerceAddressAddress'; + id?: string | null; + street?: string | null; + buildingNumber?: string | null; + locality?: string | null; + region?: string | null; + postcode?: string | null; + businessAddress?: { + __typename?: 'IoRestorecommerceAddressBusinessAddress'; + name?: string | null; + } | null; + addressAddition?: { + __typename?: 'IoRestorecommerceAddressAddressAddition'; + field1?: string | null; + field2?: string | null; + } | null; + country?: { + __typename?: 'IoRestorecommerceCountryCountry'; + id?: string | null; + name?: string | null; + countryCode?: string | null; + } | null; + residentialAddress?: { + __typename?: 'IoRestorecommerceAddressResidentialAddress'; + title?: string | null; + givenName?: string | null; + midName?: string | null; + familyName?: string | null; + } | null; + } | null; + } | null; totalAmounts?: Array<{ __typename?: 'IoRestorecommerceAmountAmount'; gross?: number | null; @@ -8228,11 +8273,15 @@ export type OrderingOrderMutateMutation = { id?: string | null; customerOrderNr?: string | null; notificationEmail?: string | null; + shopId?: string | null; orderState?: IoRestorecommerceOrderOrderState | null; items?: Array<{ __typename?: 'IoRestorecommerceOrderItem'; id?: string | null; quantity?: number | null; + productId?: string | null; + variantId?: string | null; + parentItemId?: string | null; product?: { __typename?: 'IoRestorecommerceProductProduct'; id?: string | null; @@ -8662,6 +8711,47 @@ export type OrderingOrderMutateMutation = { } | null; } | null; } | null; + billingAddress?: { + __typename?: 'IoRestorecommerceAddressBillingAddress'; + comments?: string | null; + contact?: { + __typename?: 'IoRestorecommerceAddressContact'; + name?: string | null; + email?: string | null; + phone?: string | null; + } | null; + address?: { + __typename?: 'IoRestorecommerceAddressAddress'; + id?: string | null; + street?: string | null; + buildingNumber?: string | null; + locality?: string | null; + region?: string | null; + postcode?: string | null; + businessAddress?: { + __typename?: 'IoRestorecommerceAddressBusinessAddress'; + name?: string | null; + } | null; + addressAddition?: { + __typename?: 'IoRestorecommerceAddressAddressAddition'; + field1?: string | null; + field2?: string | null; + } | null; + country?: { + __typename?: 'IoRestorecommerceCountryCountry'; + id?: string | null; + name?: string | null; + countryCode?: string | null; + } | null; + residentialAddress?: { + __typename?: 'IoRestorecommerceAddressResidentialAddress'; + title?: string | null; + givenName?: string | null; + midName?: string | null; + familyName?: string | null; + } | null; + } | null; + } | null; totalAmounts?: Array<{ __typename?: 'IoRestorecommerceAmountAmount'; gross?: number | null; @@ -8764,11 +8854,15 @@ export type OrderingOrderReadQuery = { id?: string | null; customerOrderNr?: string | null; notificationEmail?: string | null; + shopId?: string | null; orderState?: IoRestorecommerceOrderOrderState | null; items?: Array<{ __typename?: 'IoRestorecommerceOrderItem'; id?: string | null; quantity?: number | null; + productId?: string | null; + variantId?: string | null; + parentItemId?: string | null; product?: { __typename?: 'IoRestorecommerceProductProduct'; id?: string | null; @@ -9198,6 +9292,47 @@ export type OrderingOrderReadQuery = { } | null; } | null; } | null; + billingAddress?: { + __typename?: 'IoRestorecommerceAddressBillingAddress'; + comments?: string | null; + contact?: { + __typename?: 'IoRestorecommerceAddressContact'; + name?: string | null; + email?: string | null; + phone?: string | null; + } | null; + address?: { + __typename?: 'IoRestorecommerceAddressAddress'; + id?: string | null; + street?: string | null; + buildingNumber?: string | null; + locality?: string | null; + region?: string | null; + postcode?: string | null; + businessAddress?: { + __typename?: 'IoRestorecommerceAddressBusinessAddress'; + name?: string | null; + } | null; + addressAddition?: { + __typename?: 'IoRestorecommerceAddressAddressAddition'; + field1?: string | null; + field2?: string | null; + } | null; + country?: { + __typename?: 'IoRestorecommerceCountryCountry'; + id?: string | null; + name?: string | null; + countryCode?: string | null; + } | null; + residentialAddress?: { + __typename?: 'IoRestorecommerceAddressResidentialAddress'; + title?: string | null; + givenName?: string | null; + midName?: string | null; + familyName?: string | null; + } | null; + } | null; + } | null; totalAmounts?: Array<{ __typename?: 'IoRestorecommerceAmountAmount'; gross?: number | null; @@ -9558,10 +9693,14 @@ export const OrderFragmentFragmentDoc = gql` id customerOrderNr notificationEmail + shopId orderState items { id quantity + productId + variantId + parentItemId product { ...ProductFragment } @@ -9618,6 +9757,40 @@ export const OrderFragmentFragmentDoc = gql` } } } + billingAddress { + comments + contact { + name + email + phone + } + address { + id + street + buildingNumber + locality + region + businessAddress { + name + } + addressAddition { + field1 + field2 + } + country { + id + name + countryCode + } + postcode + residentialAddress { + title + givenName + midName + familyName + } + } + } totalAmounts { currency { name diff --git a/packages/modules/order/src/lib/components/order-edit.component.ts b/packages/modules/order/src/lib/components/order-edit.component.ts index 5da2d85c..8808f631 100644 --- a/packages/modules/order/src/lib/components/order-edit.component.ts +++ b/packages/modules/order/src/lib/components/order-edit.component.ts @@ -1,4 +1,9 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + ElementRef, + ViewChild, +} from '@angular/core'; import { Router } from '@angular/router'; import { combineLatest } from 'rxjs'; import { map, tap } from 'rxjs/operators'; @@ -6,33 +11,219 @@ import { map, tap } from 'rxjs/operators'; import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; import { ROUTER } from '@console-core/config'; +import { + IIoRestorecommerceOrderItem, + IIoRestorecommerceOrderOrder, + IoRestorecommerceAmountAmount, + IoRestorecommerceOrderItem, + ModeType, +} from '@console-core/graphql'; import { OrderFacade, RouterFacade, filterEmptyAndNullishAndUndefined, } from '@console-core/state'; +import { IOrder } from '@console-core/types'; import { buildOrderSchema } from '../jss-forms'; +export const transformOrderToInput = ( + order: IOrder +): IIoRestorecommerceOrderOrder => { + const inputItems: IIoRestorecommerceOrderItem[] = order.items + ? order.items.map( + (item: IoRestorecommerceOrderItem): IIoRestorecommerceOrderItem => { + return { + // id: item.id, + productId: item.productId, + variantId: item.variantId, + parentItemId: item.parentItemId, + quantity: item.quantity, + unitPrice: { + regularPrice: item.unitPrice?.regularPrice, + sale: item.unitPrice?.sale, + salePrice: item.unitPrice?.salePrice, + currencyId: item.unitPrice?.currencyId, + }, + }; + } + ) + : []; + + const totalAmounts = order.totalAmounts + ? order.totalAmounts.map((orderAmount): IoRestorecommerceAmountAmount => { + return { + gross: orderAmount.gross, + net: orderAmount.net, + currencyId: orderAmount.currencyId, + }; + }) + : []; + + return { + id: order.id, + shopId: order.shopId, + notificationEmail: order.notificationEmail, + orderState: order.orderState, + customerType: order.customerType, + customerVatId: order.customerVatId, + paymentMethodId: order.paymentMethodId, + shippingAddress: { + address: { + // id: order.shippingAddress?.address?.id, + locality: order.shippingAddress?.address?.locality, + street: order.shippingAddress?.address?.street, + region: order.shippingAddress?.address?.region, + countryId: order.shippingAddress?.address?.countryId, + buildingNumber: order.shippingAddress?.address?.buildingNumber, + postcode: order.shippingAddress?.address?.postcode, + // altitude: null, + // addressAddition: { + // field1: '', + // field2: '', + // }, + // businessAddress: { + // name: order.shippingAddress?.address?.businessAddress?.name, + // }, + // residentialAddress: { + // title: null, + // givenName: null, + // midName: null, + // familyName: null, + // }, + // geoCoordinates: { + // latitude: null, + // longitude: null, + // }, + // packStation: { + // provider: null, + // stationNumber: null, + // postNumber: null, + // }, + }, + // contact: { + // name: null, + // email: null, + // phone: null, + // }, + // comments: null, + }, + billingAddress: { + address: { + // id: order.billingAddress?.address?.id, + postcode: order.billingAddress?.address?.postcode, + countryId: order.billingAddress?.address?.countryId, + locality: order.billingAddress?.address?.locality, + street: order.billingAddress?.address?.street, + region: order.billingAddress?.address?.region, + // altitude: null, + buildingNumber: order.billingAddress?.address?.buildingNumber, + // geoCoordinates: { + // latitude: null, + // longitude: null, + // }, + // addressAddition: { + // field1: '', + // field2: '', + // }, + // businessAddress: { + // name: order.billingAddress?.address?.businessAddress?.name, + // }, + // residentialAddress: { + // title: null, + // givenName: null, + // midName: null, + // familyName: null, + // }, + // packStation: { + // provider: null, + // stationNumber: null, + // postNumber: null, + // }, + }, + // contact: { + // name: null, + // email: null, + // phone: null, + // }, + // comments: null, + }, + totalAmounts: [...totalAmounts], + items: [...inputItems], + }; +}; + @Component({ selector: 'app-module-order-edit', template: ` -
- + +
+ + +
+
+ + +
+
+
`, + styles: [ + ` + :host { + display: block; + height: 100%; + } + + form { + display: flex; + height: 100%; + flex-direction: column; + } + + textarea { + width: 100%; + flex: 1; + } + `, + ], changeDetection: ChangeDetectionStrategy.OnPush, }) export class OrderEditComponent { schema!: VCLFormFieldSchemaRoot; update = this.orderFacade.update; + orderJSON = ''; + modified = false; + jsonError = false; + + @ViewChild('rawTextarea') + rawTextarea!: ElementRef; + readonly vm$ = combineLatest({ id: this.routerFacade.params$.pipe( map(({ id }) => id), @@ -56,9 +247,49 @@ export class OrderEditComponent { ), }); + getOrderSource(order: IOrder) { + const orderInput = transformOrderToInput(order); + console.log(order); + return JSON.stringify(orderInput, null, 4); + } + constructor( private readonly router: Router, private readonly routerFacade: RouterFacade, private readonly orderFacade: OrderFacade ) {} + + onInput() { + const textarea = this.rawTextarea.nativeElement as HTMLTextAreaElement; + this.orderJSON = textarea.value; + + this.modified = true; + + let error = ''; + + try { + JSON.stringify(JSON.parse(this.orderJSON)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + error = e.message; + } + + textarea.setCustomValidity(error ? 'Invalid JSON: ' + error : ''); + + textarea.reportValidity(); + this.jsonError = !!error; + console.log(this.orderJSON); + } + + onSave() { + console.log(); + this.update({ + items: [ + { + ...JSON.parse(this.orderJSON), + }, + ], + mode: ModeType.Update, + }); + } } diff --git a/packages/modules/ui/src/lib/components/organisms/crud/crud-main.component.html b/packages/modules/ui/src/lib/components/organisms/crud/crud-main.component.html index 3e9668e5..52e928fd 100644 --- a/packages/modules/ui/src/lib/components/organisms/crud/crud-main.component.html +++ b/packages/modules/ui/src/lib/components/organisms/crud/crud-main.component.html @@ -164,7 +164,7 @@ -
+
diff --git a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html index ea33849e..7b8e91a6 100644 --- a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html +++ b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html @@ -1,6 +1,6 @@
- +