|
|
@@ -1,6 +1,12 @@
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
-import { CancelOrderInput, Dialog, I18nService, OrderDetailFragment, OrderLineInput } from '@vendure/admin-ui/core';
|
|
|
+import {
|
|
|
+ CancelOrderInput,
|
|
|
+ Dialog,
|
|
|
+ I18nService,
|
|
|
+ OrderDetailFragment,
|
|
|
+ OrderLineInput,
|
|
|
+} from '@vendure/admin-ui/core';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'vdr-cancel-order-dialog',
|
|
|
@@ -10,6 +16,7 @@ import { CancelOrderInput, Dialog, I18nService, OrderDetailFragment, OrderLineIn
|
|
|
})
|
|
|
export class CancelOrderDialogComponent implements OnInit, Dialog<CancelOrderInput> {
|
|
|
order: OrderDetailFragment;
|
|
|
+ cancelAll = true;
|
|
|
resolveWith: (result?: CancelOrderInput) => void;
|
|
|
reason: string;
|
|
|
lineQuantities: { [lineId: string]: number } = {};
|
|
|
@@ -25,15 +32,40 @@ export class CancelOrderDialogComponent implements OnInit, Dialog<CancelOrderInp
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.lineQuantities = this.order.lines.reduce((result, line) => {
|
|
|
- return { ...result, [line.id]: 0 };
|
|
|
+ return { ...result, [line.id]: line.quantity };
|
|
|
}, {});
|
|
|
}
|
|
|
|
|
|
+ radioChanged() {
|
|
|
+ if (this.cancelAll) {
|
|
|
+ for (const line of this.order.lines) {
|
|
|
+ this.lineQuantities[line.id] = line.quantity;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (const line of this.order.lines) {
|
|
|
+ this.lineQuantities[line.id] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ checkIfAllSelected() {
|
|
|
+ for (const [lineId, quantity] of Object.entries(this.lineQuantities)) {
|
|
|
+ const quantityInOrder = this.order.lines.find(line => line.id === lineId)?.quantity;
|
|
|
+ if (quantityInOrder && quantity < quantityInOrder) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // If we got here, all of the selected quantities are equal to the order
|
|
|
+ // line quantities, i.e. everything is selected.
|
|
|
+ this.cancelAll = true;
|
|
|
+ }
|
|
|
+
|
|
|
select() {
|
|
|
this.resolveWith({
|
|
|
orderId: this.order.id,
|
|
|
lines: this.getLineInputs(),
|
|
|
reason: this.reason,
|
|
|
+ cancelShipping: this.cancelAll,
|
|
|
});
|
|
|
}
|
|
|
|