Use variant prices in add product modal (#1698)

* Replace channel price with variant price; add new price label

* Update fixtures

* Remove unused code

* Remove unused style

* Lint fix

* Remove type conversion

* lint fix

* update queries and types

* CR Fixes

* Money align right
This commit is contained in:
Wojciech Mista 2021-12-23 16:00:37 +01:00 committed by GitHub
parent ff14720e23
commit 6e09ec9bb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 466 additions and 14 deletions

View file

@ -0,0 +1,28 @@
import { Typography } from "@material-ui/core";
import React from "react";
import Money, { IMoney } from "../Money";
import { useStyles } from "./styles";
interface DiscountedPriceProps {
regularPrice: IMoney;
discountedPrice: IMoney;
}
const DiscountedPrice: React.FC<DiscountedPriceProps> = ({
regularPrice,
discountedPrice
}) => {
const classes = useStyles();
return (
<>
<Typography className={classes.strike}>
<Money money={regularPrice} />
</Typography>
<Money money={discountedPrice} />
</>
);
};
export default DiscountedPrice;

View file

@ -0,0 +1,12 @@
import { makeStyles } from "@saleor/macaw-ui";
export const useStyles = makeStyles(
theme => ({
strike: {
textDecoration: "line-through",
color: theme.palette.grey[400],
fontSize: "smaller"
}
}),
{ name: "DiscountedPrice" }
);

View file

@ -313,6 +313,9 @@ export const fragmentOrderDetails = gql`
name name
currencyCode currencyCode
slug slug
defaultCountry {
code
}
} }
isPaid isPaid
} }

View file

@ -539,6 +539,11 @@ export interface OrderDetailsFragment_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDetailsFragment_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDetailsFragment_channel { export interface OrderDetailsFragment_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -546,6 +551,7 @@ export interface OrderDetailsFragment_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDetailsFragment_channel_defaultCountry;
} }
export interface OrderDetailsFragment { export interface OrderDetailsFragment {

View file

@ -14,6 +14,7 @@ import {
orderStatusMessages, orderStatusMessages,
paymentStatusMessages paymentStatusMessages
} from "./intl"; } from "./intl";
import { OrderDetails_order_shippingAddress } from "./orders/types/OrderDetails";
import { import {
MutationResultAdditionalProps, MutationResultAdditionalProps,
PartialMutationProviderOutput, PartialMutationProviderOutput,
@ -354,6 +355,16 @@ export function findInEnum<TEnum extends {}>(needle: string, haystack: TEnum) {
throw new Error(`Key ${needle} not found in enum`); throw new Error(`Key ${needle} not found in enum`);
} }
export function addressToAddressInput<T>(
address: T & OrderDetails_order_shippingAddress
): AddressInput {
const { id, __typename, ...rest } = address;
return {
...rest,
country: findInEnum(address.country.code, CountryCode)
};
}
export function findValueInEnum<TEnum extends {}>( export function findValueInEnum<TEnum extends {}>(
needle: string, needle: string,
haystack: TEnum haystack: TEnum

View file

@ -0,0 +1,30 @@
import DiscountedPrice from "@saleor/components/DiscountedPrice/DiscountedPrice";
import Money from "@saleor/components/Money";
import { SearchOrderVariant_search_edges_node_variants_pricing } from "@saleor/orders/types/SearchOrderVariant";
import * as React from "react";
import { useStyles } from "./styles";
interface OrderPriceLabelProps {
pricing: SearchOrderVariant_search_edges_node_variants_pricing;
}
const OrderPriceLabel: React.FC<OrderPriceLabelProps> = ({ pricing }) => {
const classes = useStyles();
if (pricing.onSale) {
const { price, priceUndiscounted } = pricing;
return (
<div className={classes.percentDiscountLabelContainer}>
<DiscountedPrice
discountedPrice={price.gross}
regularPrice={priceUndiscounted.gross}
/>
</div>
);
}
return <Money money={pricing.priceUndiscounted.gross} align="right" />;
};
export default OrderPriceLabel;

View file

@ -0,0 +1,13 @@
import { makeStyles } from "@saleor/macaw-ui";
export const useStyles = makeStyles(
() => ({
percentDiscountLabelContainer: {
display: "flex",
flexDirection: "column",
alignItems: "flex-end",
justifyContent: "flex-end"
}
}),
{ name: "OrderPriceLabel" }
);

View file

@ -16,7 +16,6 @@ import ConfirmButton, {
ConfirmButtonTransitionState ConfirmButtonTransitionState
} from "@saleor/components/ConfirmButton"; } from "@saleor/components/ConfirmButton";
import FormSpacer from "@saleor/components/FormSpacer"; import FormSpacer from "@saleor/components/FormSpacer";
import Money from "@saleor/components/Money";
import ResponsiveTable from "@saleor/components/ResponsiveTable"; import ResponsiveTable from "@saleor/components/ResponsiveTable";
import TableCellAvatar from "@saleor/components/TableCellAvatar"; import TableCellAvatar from "@saleor/components/TableCellAvatar";
import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment"; import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment";
@ -36,6 +35,7 @@ import {
SearchOrderVariant_search_edges_node, SearchOrderVariant_search_edges_node,
SearchOrderVariant_search_edges_node_variants SearchOrderVariant_search_edges_node_variants
} from "../../types/SearchOrderVariant"; } from "../../types/SearchOrderVariant";
import OrderPriceLabel from "../OrderPriceLabel/OrderPriceLabel";
const useStyles = makeStyles( const useStyles = makeStyles(
theme => ({ theme => ({
@ -365,9 +365,7 @@ const OrderProductAddDialog: React.FC<OrderProductAddDialogProps> = props => {
)} )}
</TableCell> </TableCell>
<TableCell className={classes.textRight}> <TableCell className={classes.textRight}>
{variant?.channelListings[0]?.price && ( <OrderPriceLabel pricing={variant.pricing} />
<Money money={variant.channelListings[0].price} />
)}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}

View file

@ -837,7 +837,11 @@ export const order = (placeholder: string): OrderDetails_order => ({
currencyCode: "USD", currencyCode: "USD",
id: "123454", id: "123454",
isActive: true, isActive: true,
name: "Default Channel" name: "Default Channel",
defaultCountry: {
code: "CA",
__typename: "CountryDisplay"
}
}, },
created: "2018-09-11T09:37:28.185874+00:00", created: "2018-09-11T09:37:28.185874+00:00",
customerNote: "Lorem ipsum dolor sit amet", customerNote: "Lorem ipsum dolor sit amet",
@ -1424,7 +1428,11 @@ export const draftOrder = (placeholder: string): OrderDetails_order => ({
currencyCode: "USD", currencyCode: "USD",
id: "123454", id: "123454",
isActive: true, isActive: true,
name: "Default Channel" name: "Default Channel",
defaultCountry: {
code: "CA",
__typename: "CountryDisplay"
}
}, },
created: "2018-09-20T23:23:39.811428+00:00", created: "2018-09-20T23:23:39.811428+00:00",
customerNote: "Lorem ipsum dolor sit", customerNote: "Lorem ipsum dolor sit",
@ -1695,7 +1703,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjAy", id: "UHJvZHVjdFZhcmlhbnQ6MjAy",
name: "500ml", name: "500ml",
sku: "93855755" sku: "93855755",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
}, },
{ {
__typename: "ProductVariant" as "ProductVariant", __typename: "ProductVariant" as "ProductVariant",
@ -1733,7 +1761,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjAz", id: "UHJvZHVjdFZhcmlhbnQ6MjAz",
name: "1l", name: "1l",
sku: "43226647" sku: "43226647",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
}, },
{ {
__typename: "ProductVariant" as "ProductVariant", __typename: "ProductVariant" as "ProductVariant",
@ -1771,7 +1819,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjA0", id: "UHJvZHVjdFZhcmlhbnQ6MjA0",
name: "2l", name: "2l",
sku: "80884671" sku: "80884671",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
} }
] ]
}, },
@ -1820,7 +1888,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjEx", id: "UHJvZHVjdFZhcmlhbnQ6MjEx",
name: "500ml", name: "500ml",
sku: "43200242" sku: "43200242",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
}, },
{ {
__typename: "ProductVariant" as "ProductVariant", __typename: "ProductVariant" as "ProductVariant",
@ -1858,7 +1946,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjEy", id: "UHJvZHVjdFZhcmlhbnQ6MjEy",
name: "1l", name: "1l",
sku: "79129513" sku: "79129513",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
}, },
{ {
__typename: "ProductVariant" as "ProductVariant", __typename: "ProductVariant" as "ProductVariant",
@ -1896,7 +2004,27 @@ export const orderLineSearch = (
], ],
id: "UHJvZHVjdFZhcmlhbnQ6MjEz", id: "UHJvZHVjdFZhcmlhbnQ6MjEz",
name: "2l", name: "2l",
sku: "75799450" sku: "75799450",
pricing: {
__typename: "VariantPricingInfo",
onSale: false,
price: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
},
priceUndiscounted: {
__typename: "TaxedMoney",
gross: {
amount: 1,
currency: "USD",
__typename: "Money"
}
}
}
} }
] ]
} }

View file

@ -169,11 +169,13 @@ export const useOrderQuery = makeQuery<OrderDetails, OrderDetailsVariables>(
); );
export const searchOrderVariant = gql` export const searchOrderVariant = gql`
${fragmentMoney}
query SearchOrderVariant( query SearchOrderVariant(
$channel: String! $channel: String!
$first: Int! $first: Int!
$query: String! $query: String!
$after: String $after: String
$address: AddressInput
) { ) {
search: products( search: products(
first: $first first: $first
@ -192,6 +194,19 @@ export const searchOrderVariant = gql`
id id
name name
sku sku
pricing(address: $address) {
priceUndiscounted {
gross {
...Money
}
}
price {
gross {
...Money
}
}
onSale
}
channelListings { channelListings {
channel { channel {
id id

View file

@ -548,6 +548,11 @@ export interface FulfillOrder_orderFulfill_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface FulfillOrder_orderFulfill_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface FulfillOrder_orderFulfill_order_channel { export interface FulfillOrder_orderFulfill_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -555,6 +560,7 @@ export interface FulfillOrder_orderFulfill_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: FulfillOrder_orderFulfill_order_channel_defaultCountry;
} }
export interface FulfillOrder_orderFulfill_order { export interface FulfillOrder_orderFulfill_order {

View file

@ -546,6 +546,11 @@ export interface OrderCancel_orderCancel_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderCancel_orderCancel_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderCancel_orderCancel_order_channel { export interface OrderCancel_orderCancel_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderCancel_orderCancel_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderCancel_orderCancel_order_channel_defaultCountry;
} }
export interface OrderCancel_orderCancel_order { export interface OrderCancel_orderCancel_order {

View file

@ -546,6 +546,11 @@ export interface OrderCapture_orderCapture_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderCapture_orderCapture_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderCapture_orderCapture_order_channel { export interface OrderCapture_orderCapture_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderCapture_orderCapture_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderCapture_orderCapture_order_channel_defaultCountry;
} }
export interface OrderCapture_orderCapture_order { export interface OrderCapture_orderCapture_order {

View file

@ -546,6 +546,11 @@ export interface OrderConfirm_orderConfirm_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderConfirm_orderConfirm_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderConfirm_orderConfirm_order_channel { export interface OrderConfirm_orderConfirm_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderConfirm_orderConfirm_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderConfirm_orderConfirm_order_channel_defaultCountry;
} }
export interface OrderConfirm_orderConfirm_order { export interface OrderConfirm_orderConfirm_order {

View file

@ -539,6 +539,11 @@ export interface OrderDetails_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDetails_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDetails_order_channel { export interface OrderDetails_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -546,6 +551,7 @@ export interface OrderDetails_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDetails_order_channel_defaultCountry;
} }
export interface OrderDetails_order { export interface OrderDetails_order {

View file

@ -546,6 +546,11 @@ export interface OrderDiscountAdd_orderDiscountAdd_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDiscountAdd_orderDiscountAdd_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDiscountAdd_orderDiscountAdd_order_channel { export interface OrderDiscountAdd_orderDiscountAdd_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDiscountAdd_orderDiscountAdd_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDiscountAdd_orderDiscountAdd_order_channel_defaultCountry;
} }
export interface OrderDiscountAdd_orderDiscountAdd_order { export interface OrderDiscountAdd_orderDiscountAdd_order {

View file

@ -546,6 +546,11 @@ export interface OrderDiscountDelete_orderDiscountDelete_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDiscountDelete_orderDiscountDelete_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDiscountDelete_orderDiscountDelete_order_channel { export interface OrderDiscountDelete_orderDiscountDelete_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDiscountDelete_orderDiscountDelete_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDiscountDelete_orderDiscountDelete_order_channel_defaultCountry;
} }
export interface OrderDiscountDelete_orderDiscountDelete_order { export interface OrderDiscountDelete_orderDiscountDelete_order {

View file

@ -546,6 +546,11 @@ export interface OrderDiscountUpdate_orderDiscountUpdate_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel { export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDiscountUpdate_orderDiscountUpdate_order_channel_defaultCountry;
} }
export interface OrderDiscountUpdate_orderDiscountUpdate_order { export interface OrderDiscountUpdate_orderDiscountUpdate_order {

View file

@ -546,6 +546,11 @@ export interface OrderDraftCancel_draftOrderDelete_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDraftCancel_draftOrderDelete_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDraftCancel_draftOrderDelete_order_channel { export interface OrderDraftCancel_draftOrderDelete_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDraftCancel_draftOrderDelete_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDraftCancel_draftOrderDelete_order_channel_defaultCountry;
} }
export interface OrderDraftCancel_draftOrderDelete_order { export interface OrderDraftCancel_draftOrderDelete_order {

View file

@ -546,6 +546,11 @@ export interface OrderDraftFinalize_draftOrderComplete_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDraftFinalize_draftOrderComplete_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDraftFinalize_draftOrderComplete_order_channel { export interface OrderDraftFinalize_draftOrderComplete_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDraftFinalize_draftOrderComplete_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDraftFinalize_draftOrderComplete_order_channel_defaultCountry;
} }
export interface OrderDraftFinalize_draftOrderComplete_order { export interface OrderDraftFinalize_draftOrderComplete_order {

View file

@ -546,6 +546,11 @@ export interface OrderDraftUpdate_draftOrderUpdate_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderDraftUpdate_draftOrderUpdate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderDraftUpdate_draftOrderUpdate_order_channel { export interface OrderDraftUpdate_draftOrderUpdate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderDraftUpdate_draftOrderUpdate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderDraftUpdate_draftOrderUpdate_order_channel_defaultCountry;
} }
export interface OrderDraftUpdate_draftOrderUpdate_order { export interface OrderDraftUpdate_draftOrderUpdate_order {

View file

@ -546,6 +546,11 @@ export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_invoices
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel { export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderFulfillmentApprove_orderFulfillmentApprove_order_channel_defaultCountry;
} }
export interface OrderFulfillmentApprove_orderFulfillmentApprove_order { export interface OrderFulfillmentApprove_orderFulfillmentApprove_order {

View file

@ -546,6 +546,11 @@ export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel { export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderFulfillmentCancel_orderFulfillmentCancel_order_channel_defaultCountry;
} }
export interface OrderFulfillmentCancel_orderFulfillmentCancel_order { export interface OrderFulfillmentCancel_orderFulfillmentCancel_order {

View file

@ -648,6 +648,11 @@ export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_o
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel { export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -655,6 +660,7 @@ export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_o
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel_defaultCountry;
} }
export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order { export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order {

View file

@ -546,6 +546,11 @@ export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_o
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel { export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_o
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel_defaultCountry;
} }
export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order { export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order {

View file

@ -546,6 +546,11 @@ export interface OrderLineDelete_orderLineDelete_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderLineDelete_orderLineDelete_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderLineDelete_orderLineDelete_order_channel { export interface OrderLineDelete_orderLineDelete_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderLineDelete_orderLineDelete_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderLineDelete_orderLineDelete_order_channel_defaultCountry;
} }
export interface OrderLineDelete_orderLineDelete_order { export interface OrderLineDelete_orderLineDelete_order {

View file

@ -546,6 +546,11 @@ export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_invoices
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel { export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderLineDiscountRemove_orderLineDiscountRemove_order_channel_defaultCountry;
} }
export interface OrderLineDiscountRemove_orderLineDiscountRemove_order { export interface OrderLineDiscountRemove_orderLineDiscountRemove_order {

View file

@ -546,6 +546,11 @@ export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_invoices
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel { export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel_defaultCountry;
} }
export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order { export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order {

View file

@ -546,6 +546,11 @@ export interface OrderLineUpdate_orderLineUpdate_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderLineUpdate_orderLineUpdate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderLineUpdate_orderLineUpdate_order_channel { export interface OrderLineUpdate_orderLineUpdate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderLineUpdate_orderLineUpdate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderLineUpdate_orderLineUpdate_order_channel_defaultCountry;
} }
export interface OrderLineUpdate_orderLineUpdate_order { export interface OrderLineUpdate_orderLineUpdate_order {

View file

@ -546,6 +546,11 @@ export interface OrderLinesAdd_orderLinesCreate_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderLinesAdd_orderLinesCreate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderLinesAdd_orderLinesCreate_order_channel { export interface OrderLinesAdd_orderLinesCreate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderLinesAdd_orderLinesCreate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderLinesAdd_orderLinesCreate_order_channel_defaultCountry;
} }
export interface OrderLinesAdd_orderLinesCreate_order { export interface OrderLinesAdd_orderLinesCreate_order {

View file

@ -546,6 +546,11 @@ export interface OrderMarkAsPaid_orderMarkAsPaid_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel { export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderMarkAsPaid_orderMarkAsPaid_order_channel_defaultCountry;
} }
export interface OrderMarkAsPaid_orderMarkAsPaid_order { export interface OrderMarkAsPaid_orderMarkAsPaid_order {

View file

@ -546,6 +546,11 @@ export interface OrderRefund_orderRefund_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderRefund_orderRefund_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderRefund_orderRefund_order_channel { export interface OrderRefund_orderRefund_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderRefund_orderRefund_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderRefund_orderRefund_order_channel_defaultCountry;
} }
export interface OrderRefund_orderRefund_order { export interface OrderRefund_orderRefund_order {

View file

@ -554,6 +554,11 @@ export interface OrderShippingMethodUpdate_orderUpdateShipping_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel { export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -561,6 +566,7 @@ export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderShippingMethodUpdate_orderUpdateShipping_order_channel_defaultCountry;
} }
export interface OrderShippingMethodUpdate_orderUpdateShipping_order { export interface OrderShippingMethodUpdate_orderUpdateShipping_order {

View file

@ -546,6 +546,11 @@ export interface OrderUpdate_orderUpdate_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderUpdate_orderUpdate_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderUpdate_orderUpdate_order_channel { export interface OrderUpdate_orderUpdate_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderUpdate_orderUpdate_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderUpdate_orderUpdate_order_channel_defaultCountry;
} }
export interface OrderUpdate_orderUpdate_order { export interface OrderUpdate_orderUpdate_order {

View file

@ -546,6 +546,11 @@ export interface OrderVoid_orderVoid_order_invoices {
status: JobStatusEnum; status: JobStatusEnum;
} }
export interface OrderVoid_orderVoid_order_channel_defaultCountry {
__typename: "CountryDisplay";
code: string;
}
export interface OrderVoid_orderVoid_order_channel { export interface OrderVoid_orderVoid_order_channel {
__typename: "Channel"; __typename: "Channel";
isActive: boolean; isActive: boolean;
@ -553,6 +558,7 @@ export interface OrderVoid_orderVoid_order_channel {
name: string; name: string;
currencyCode: string; currencyCode: string;
slug: string; slug: string;
defaultCountry: OrderVoid_orderVoid_order_channel_defaultCountry;
} }
export interface OrderVoid_orderVoid_order { export interface OrderVoid_orderVoid_order {

View file

@ -3,6 +3,8 @@
// @generated // @generated
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { AddressInput } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL query operation: SearchOrderVariant // GraphQL query operation: SearchOrderVariant
// ==================================================== // ====================================================
@ -12,6 +14,35 @@ export interface SearchOrderVariant_search_edges_node_thumbnail {
url: string; url: string;
} }
export interface SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted_gross {
__typename: "Money";
amount: number;
currency: string;
}
export interface SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted {
__typename: "TaxedMoney";
gross: SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted_gross;
}
export interface SearchOrderVariant_search_edges_node_variants_pricing_price_gross {
__typename: "Money";
amount: number;
currency: string;
}
export interface SearchOrderVariant_search_edges_node_variants_pricing_price {
__typename: "TaxedMoney";
gross: SearchOrderVariant_search_edges_node_variants_pricing_price_gross;
}
export interface SearchOrderVariant_search_edges_node_variants_pricing {
__typename: "VariantPricingInfo";
priceUndiscounted: SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted | null;
price: SearchOrderVariant_search_edges_node_variants_pricing_price | null;
onSale: boolean | null;
}
export interface SearchOrderVariant_search_edges_node_variants_channelListings_channel { export interface SearchOrderVariant_search_edges_node_variants_channelListings_channel {
__typename: "Channel"; __typename: "Channel";
id: string; id: string;
@ -37,6 +68,7 @@ export interface SearchOrderVariant_search_edges_node_variants {
id: string; id: string;
name: string; name: string;
sku: string | null; sku: string | null;
pricing: SearchOrderVariant_search_edges_node_variants_pricing | null;
channelListings: SearchOrderVariant_search_edges_node_variants_channelListings[] | null; channelListings: SearchOrderVariant_search_edges_node_variants_channelListings[] | null;
} }
@ -76,4 +108,5 @@ export interface SearchOrderVariantVariables {
first: number; first: number;
query: string; query: string;
after?: string | null; after?: string | null;
address?: AddressInput | null;
} }

View file

@ -1,7 +1,13 @@
import { IMoney, subtractMoney } from "@saleor/components/Money"; import { IMoney, subtractMoney } from "@saleor/components/Money";
import { WarehouseFragment } from "@saleor/fragments/types/WarehouseFragment"; import { WarehouseFragment } from "@saleor/fragments/types/WarehouseFragment";
import { FormsetData } from "@saleor/hooks/useFormset"; import { FormsetData } from "@saleor/hooks/useFormset";
import { FulfillmentStatus, OrderErrorCode } from "@saleor/types/globalTypes"; import { addressToAddressInput } from "@saleor/misc";
import {
AddressInput,
CountryCode,
FulfillmentStatus,
OrderErrorCode
} from "@saleor/types/globalTypes";
import { import {
LineItemData, LineItemData,
@ -298,3 +304,17 @@ export const isStockError = (
return isQuantityLargerThanAvailable || isError; return isQuantityLargerThanAvailable || isError;
}; };
export const getVariantSearchAddress = (
order: OrderDetails_order
): AddressInput => {
if (order.shippingAddress) {
return addressToAddressInput(order.shippingAddress);
}
if (order.billingAddress) {
return addressToAddressInput(order.billingAddress);
}
return { country: order.channel.defaultCountry.code as CountryCode };
};

View file

@ -13,6 +13,7 @@ import {
} from "@saleor/orders/components/OrderCustomerChangeDialog/form"; } from "@saleor/orders/components/OrderCustomerChangeDialog/form";
import OrderCustomerChangeDialog from "@saleor/orders/components/OrderCustomerChangeDialog/OrderCustomerChangeDialog"; import OrderCustomerChangeDialog from "@saleor/orders/components/OrderCustomerChangeDialog/OrderCustomerChangeDialog";
import { OrderDetails } from "@saleor/orders/types/OrderDetails"; import { OrderDetails } from "@saleor/orders/types/OrderDetails";
import { getVariantSearchAddress } from "@saleor/orders/utils/data";
import { OrderDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderDiscountProvider"; import { OrderDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderDiscountProvider";
import { OrderLineDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderLineDiscountProvider"; import { OrderLineDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderLineDiscountProvider";
import useCustomerSearch from "@saleor/searches/useCustomerSearch"; import useCustomerSearch from "@saleor/searches/useCustomerSearch";
@ -73,7 +74,11 @@ export const OrderDraftDetails: React.FC<OrderDraftDetailsProps> = ({
search: variantSearch, search: variantSearch,
result: variantSearchOpts result: variantSearchOpts
} = useOrderVariantSearch({ } = useOrderVariantSearch({
variables: { ...DEFAULT_INITIAL_SEARCH_DATA, channel: order.channel.slug } variables: {
...DEFAULT_INITIAL_SEARCH_DATA,
channel: order.channel.slug,
address: getVariantSearchAddress(order)
}
}); });
const { const {