Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Warn if order has shipping method but products are digital

dominik-zeglenf426364a81f6
diff --git a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
index 7a49fb39f2..37c67d3cfe 100644
--- a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
+++ b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
@@ -30,6 +30,7 @@ const styles = (theme: Theme) =>
interface ActionDialogProps extends WithStyles<typeof styles> {
children?: React.ReactNode;
+ confirmButtonLabel?: string;
confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
title: string;
@@ -42,6 +43,7 @@ const ActionDialog = withStyles(styles, { name: "ActionDialog" })(
({
children,
classes,
+ confirmButtonLabel,
confirmButtonState,
open,
title,
@@ -65,9 +67,10 @@ const ActionDialog = withStyles(styles, { name: "ActionDialog" })(
[classes.deleteButton]: variant === "delete"
})}
>
- {variant === "delete"
- ? i18n.t("Delete", { context: "button" })
- : i18n.t("Confirm", { context: "button" })}
+ {confirmButtonLabel ||
+ (variant === "delete"
+ ? i18n.t("Delete", { context: "button" })
+ : i18n.t("Confirm", { context: "button" }))}
</ConfirmButton>
</DialogActions>
</Dialog>
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
index 529fce302d..7c8307ba49 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
@@ -9,7 +9,8 @@ export type OrderDraftFinalizeWarning =
| "no-shipping"
| "no-billing"
| "no-user"
- | "no-shipping-method";
+ | "no-shipping-method"
+ | "unnecessary-shipping-method";
export interface OrderDraftFinalizeDialogProps {
confirmButtonState: ConfirmButtonTransitionState;
@@ -30,6 +31,8 @@ const warningToText = (warning: OrderDraftFinalizeWarning) => {
return i18n.t("No user information");
case "no-shipping-method":
return i18n.t("Some products require shipping, but no method provided");
+ case "unnecessary-shipping-method":
+ return i18n.t("Shipping method provided, but no product requires it");
}
};
@@ -50,18 +53,26 @@ const OrderDraftFinalizeDialog: React.StatelessComponent<
title={i18n.t("Finalize draft order", {
context: "modal title"
})}
+ confirmButtonLabel={
+ warnings.length > 0 ? i18n.t("Finalize anyway") : i18n.t("Finalize")
+ }
confirmButtonState={confirmButtonState}
+ variant={warnings.length > 0 ? "delete" : "default"}
>
- <DialogContentText>
+ <DialogContentText component="div">
{warnings.length > 0 && (
- <p>
- {i18n.t("There are missing informations about this order.")}
+ <>
+ <p>
+ {i18n.t(
+ "There are missing or incorrect informations about this order:"
+ )}
+ </p>
<ul>
{warnings.map(warning => (
- <li>{warningToText(warning)}</li>
+ <li key={warning}>{warningToText(warning)}</li>
))}
</ul>
- </p>
+ </>
)}
<span
dangerouslySetInnerHTML={{
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
index da48339db5..e78e356731 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
@@ -78,6 +78,14 @@ const orderDraftFinalizeWarnings = (order: OrderDetails_order) => {
) {
warnings.push("no-shipping-method");
}
+ if (
+ order &&
+ order.lines &&
+ order.lines.filter(line => line.isShippingRequired).length === 0 &&
+ order.shippingMethod !== null
+ ) {
+ warnings.push("unnecessary-shipping-method");
+ }
return warnings;
};