Skip to content

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

Fix simple product editing

dominik-zeglen9d4cbb6df26d
diff --git a/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx b/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx
index fe5af9704c..d0b115895f 100644
--- a/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx
@@ -11,6 +11,8 @@ import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { ProductDetails_product } from "../../types/ProductDetails";
const styles = (theme: Theme) =>
createStyles({
@@ -27,11 +29,12 @@ interface ProductStockProps extends WithStyles<typeof styles> {
stockQuantity: number;
};
disabled: boolean;
+ product: ProductDetails_product;
onChange: (event: React.ChangeEvent<any>) => void;
}
const ProductStock = withStyles(styles, { name: "ProductStock" })(
- ({ classes, data, disabled, onChange }: ProductStockProps) => (
+ ({ classes, data, disabled, product, onChange }: ProductStockProps) => (
<Card>
<CardTitle title={i18n.t("Inventory")} />
<CardContent>
@@ -45,11 +48,14 @@ const ProductStock = withStyles(styles, { name: "ProductStock" })(
/>
<TextField
disabled={disabled}
- name="stockInventory"
+ name="stockQuantity"
label={i18n.t("Inventory")}
value={data.stockQuantity}
type="number"
onChange={onChange}
+ helperText={i18n.t("Allocated: {{ quantity }}", {
+ quantity: maybe(() => product.variants[0].quantityAllocated)
+ })}
/>
</div>
</CardContent>
diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index ff86834620..ac421994e0 100644
--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -18,7 +18,7 @@ import {
ProductDetails_product,
ProductDetails_product_attributes_attribute,
ProductDetails_product_images,
- ProductDetails_product_variants_priceOverride
+ ProductDetails_product_variants
} from "../../types/ProductDetails";
import ProductAvailabilityForm from "../ProductAvailabilityForm";
import ProductDetailsForm from "../ProductDetailsForm";
@@ -65,14 +65,7 @@ interface ProductUpdateProps extends WithStyles<typeof styles> {
id: string;
name: string;
}>;
- variants?: Array<{
- id: string;
- sku: string;
- name: string;
- priceOverride?: ProductDetails_product_variants_priceOverride;
- stockQuantity: number;
- margin: number;
- }>;
+ variants: ProductDetails_product_variants[];
images?: ProductDetails_product_images[];
product?: ProductDetails_product;
header: string;
@@ -205,7 +198,7 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(
product.productType && product.productType.hasVariants
? undefined
: variants && variants[0]
- ? variants[0].stockQuantity
+ ? variants[0].quantity
: undefined
}
: {
@@ -293,6 +286,7 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(
<ProductStock
data={data}
disabled={disabled}
+ product={product}
onChange={change}
/>
)}
diff --git a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
index 64e3498a17..b5cdcc0e0c 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
@@ -23,6 +23,7 @@ import Skeleton from "../../../components/Skeleton";
import StatusLabel from "../../../components/StatusLabel";
import i18n from "../../../i18n";
import { renderCollection } from "../../../misc";
+import { ProductDetails_product_variants } from "../../types/ProductDetails";
import { ProductVariant_costPrice } from "../../types/ProductVariant";
const styles = (theme: Theme) =>
@@ -45,14 +46,7 @@ const styles = (theme: Theme) =>
interface ProductVariantsProps extends WithStyles<typeof styles> {
disabled?: boolean;
- variants?: Array<{
- id: string;
- sku: string;
- name: string;
- priceOverride?: ProductVariant_costPrice;
- stockQuantity: number;
- margin: number;
- }>;
+ variants: ProductDetails_product_variants[];
fallbackPrice?: ProductVariant_costPrice;
onAttributesEdit: () => void;
onRowClick: (id: string) => () => void;
diff --git a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
index 2203e3aacf..f52ddd051a 100644
--- a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
@@ -6,7 +6,8 @@ import {
TypedProductDeleteMutation,
TypedProductImageCreateMutation,
TypedProductImageDeleteMutation,
- TypedProductUpdateMutation
+ TypedProductUpdateMutation,
+ TypedSimpleProductUpdateMutation
} from "../mutations";
import { ProductDelete, ProductDeleteVariables } from "../types/ProductDelete";
import { ProductDetails_product } from "../types/ProductDetails";
@@ -23,6 +24,10 @@ import {
ProductImageReorderVariables
} from "../types/ProductImageReorder";
import { ProductUpdate, ProductUpdateVariables } from "../types/ProductUpdate";
+import {
+ SimpleProductUpdate,
+ SimpleProductUpdateVariables
+} from "../types/SimpleProductUpdate";
import ProductImagesReorderProvider from "./ProductImagesReorder";
interface ProductUpdateOperationsProps {
@@ -49,6 +54,10 @@ interface ProductUpdateOperationsProps {
ProductUpdate,
ProductUpdateVariables
>;
+ updateSimpleProduct: PartialMutationProviderOutput<
+ SimpleProductUpdate,
+ SimpleProductUpdateVariables
+ >;
}
) => React.ReactNode;
onDelete?: (data: ProductDelete) => void;
@@ -86,25 +95,34 @@ const ProductUpdateOperations: React.StatelessComponent<
<TypedProductImageDeleteMutation
onCompleted={onImageDelete}
>
- {(...deleteProductImage) =>
- children({
- createProductImage: getMutationProviderData(
- ...createProductImage
- ),
- deleteProduct: getMutationProviderData(
- ...deleteProduct
- ),
- deleteProductImage: getMutationProviderData(
- ...deleteProductImage
- ),
- reorderProductImages: getMutationProviderData(
- ...reorderProductImages
- ),
- updateProduct: getMutationProviderData(
- ...updateProduct
- )
- })
- }
+ {(...deleteProductImage) => (
+ <TypedSimpleProductUpdateMutation
+ onCompleted={onUpdate}
+ >
+ {(...updateSimpleProduct) =>
+ children({
+ createProductImage: getMutationProviderData(
+ ...createProductImage
+ ),
+ deleteProduct: getMutationProviderData(
+ ...deleteProduct
+ ),
+ deleteProductImage: getMutationProviderData(
+ ...deleteProductImage
+ ),
+ reorderProductImages: getMutationProviderData(
+ ...reorderProductImages
+ ),
+ updateProduct: getMutationProviderData(
+ ...updateProduct
+ ),
+ updateSimpleProduct: getMutationProviderData(
+ ...updateSimpleProduct
+ )
+ })
+ }
+ </TypedSimpleProductUpdateMutation>
+ )}
</TypedProductImageDeleteMutation>
)}
</TypedProductDeleteMutation>
diff --git a/saleor/static/dashboard-next/products/mutations.ts b/saleor/static/dashboard-next/products/mutations.ts
index 1a6be0114f..fa399c9921 100644
--- a/saleor/static/dashboard-next/products/mutations.ts
+++ b/saleor/static/dashboard-next/products/mutations.ts
@@ -20,6 +20,10 @@ import {
ProductImageUpdateVariables
} from "./types/ProductImageUpdate";
import { ProductUpdate, ProductUpdateVariables } from "./types/ProductUpdate";
+import {
+ SimpleProductUpdate,
+ SimpleProductUpdateVariables
+} from "./types/SimpleProductUpdate";
import { VariantCreate, VariantCreateVariables } from "./types/VariantCreate";
import { VariantDelete, VariantDeleteVariables } from "./types/VariantDelete";
import {
@@ -138,6 +142,61 @@ export const TypedProductUpdateMutation = TypedMutation<
ProductUpdateVariables
>(productUpdateMutation);
+export const simpleProductUpdateMutation = gql`
+ ${fragmentProduct}
+ ${fragmentVariant}
+ mutation SimpleProductUpdate(
+ $id: ID!
+ $attributes: [AttributeValueInput]
+ $availableOn: Date
+ $category: ID
+ $chargeTaxes: Boolean!
+ $collections: [ID]
+ $description: String
+ $isPublished: Boolean!
+ $name: String
+ $price: Decimal
+ $productVariantId: ID!
+ $productVariantInput: ProductVariantInput!
+ ) {
+ productUpdate(
+ id: $id
+ input: {
+ attributes: $attributes
+ availableOn: $availableOn
+ category: $category
+ chargeTaxes: $chargeTaxes
+ collections: $collections
+ description: $description
+ isPublished: $isPublished
+ name: $name
+ price: $price
+ }
+ ) {
+ errors {
+ field
+ message
+ }
+ product {
+ ...Product
+ }
+ }
+ productVariantUpdate(id: $productVariantId, input: $productVariantInput) {
+ errors {
+ field
+ message
+ }
+ productVariant {
+ ...ProductVariant
+ }
+ }
+ }
+`;
+export const TypedSimpleProductUpdateMutation = TypedMutation<
+ SimpleProductUpdate,
+ SimpleProductUpdateVariables
+>(simpleProductUpdateMutation);
+
export const productCreateMutation = gql`
${fragmentProduct}
mutation ProductCreate(
diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.ts
index d3ecd5667d..1a9d623ece 100644
--- a/saleor/static/dashboard-next/products/queries.ts
+++ b/saleor/static/dashboard-next/products/queries.ts
@@ -120,8 +120,10 @@ export const fragmentProduct = gql`
priceOverride {
...Money
}
- stockQuantity
margin
+ quantity
+ quantityAllocated
+ stockQuantity
}
productType {
id
diff --git a/saleor/static/dashboard-next/products/types/Product.ts b/saleor/static/dashboard-next/products/types/Product.ts
index 39b58a4ac8..e3b5380b21 100644
--- a/saleor/static/dashboard-next/products/types/Product.ts
+++ b/saleor/static/dashboard-next/products/types/Product.ts
@@ -128,8 +128,10 @@ export interface Product_variants {
sku: string;
name: string;
priceOverride: Product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface Product_productType {
diff --git a/saleor/static/dashboard-next/products/types/ProductCreate.ts b/saleor/static/dashboard-next/products/types/ProductCreate.ts
index 2c028e319c..b2f80721fa 100644
--- a/saleor/static/dashboard-next/products/types/ProductCreate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductCreate.ts
@@ -136,8 +136,10 @@ export interface ProductCreate_productCreate_product_variants {
sku: string;
name: string;
priceOverride: ProductCreate_productCreate_product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface ProductCreate_productCreate_product_productType {
diff --git a/saleor/static/dashboard-next/products/types/ProductDetails.ts b/saleor/static/dashboard-next/products/types/ProductDetails.ts
index 1b133230f7..e539c0aed3 100644
--- a/saleor/static/dashboard-next/products/types/ProductDetails.ts
+++ b/saleor/static/dashboard-next/products/types/ProductDetails.ts
@@ -128,8 +128,10 @@ export interface ProductDetails_product_variants {
sku: string;
name: string;
priceOverride: ProductDetails_product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface ProductDetails_product_productType {
diff --git a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts b/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
index fc46d3c03c..61a5ecb7ae 100644
--- a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
@@ -134,8 +134,10 @@ export interface ProductImageCreate_productImageCreate_product_variants {
sku: string;
name: string;
priceOverride: ProductImageCreate_productImageCreate_product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface ProductImageCreate_productImageCreate_product_productType {
diff --git a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts b/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
index 53092ebaca..f183bdc7d5 100644
--- a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
@@ -134,8 +134,10 @@ export interface ProductImageUpdate_productImageUpdate_product_variants {
sku: string;
name: string;
priceOverride: ProductImageUpdate_productImageUpdate_product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface ProductImageUpdate_productImageUpdate_product_productType {
diff --git a/saleor/static/dashboard-next/products/types/ProductUpdate.ts b/saleor/static/dashboard-next/products/types/ProductUpdate.ts
index e2163b6843..4f51c1e9f4 100644
--- a/saleor/static/dashboard-next/products/types/ProductUpdate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductUpdate.ts
@@ -136,8 +136,10 @@ export interface ProductUpdate_productUpdate_product_variants {
sku: string;
name: string;
priceOverride: ProductUpdate_productUpdate_product_variants_priceOverride | null;
- stockQuantity: number;
margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
}
export interface ProductUpdate_productUpdate_product_productType {
diff --git a/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts
new file mode 100644
index 0000000000..4276b252be
--- /dev/null
+++ b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts
@@ -0,0 +1,302 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { AttributeValueInput, ProductVariantInput } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: SimpleProductUpdate
+// ====================================================
+
+export interface SimpleProductUpdate_productUpdate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_category {
+ __typename: "Category";
+ id: string;
+ name: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_collections {
+ __typename: "Collection";
+ id: string;
+ name: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_price {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_margin {
+ __typename: "Margin";
+ start: number | null;
+ stop: number | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_purchaseCost_start {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_purchaseCost_stop {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_purchaseCost {
+ __typename: "MoneyRange";
+ start: SimpleProductUpdate_productUpdate_product_purchaseCost_start | null;
+ stop: SimpleProductUpdate_productUpdate_product_purchaseCost_stop | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_attributes_attribute_values {
+ __typename: "AttributeValue";
+ name: string | null;
+ slug: string | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_attributes_attribute {
+ __typename: "Attribute";
+ id: string;
+ slug: string | null;
+ name: string | null;
+ values: (SimpleProductUpdate_productUpdate_product_attributes_attribute_values | null)[] | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_attributes_value {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_attributes {
+ __typename: "SelectedAttribute";
+ attribute: SimpleProductUpdate_productUpdate_product_attributes_attribute;
+ value: SimpleProductUpdate_productUpdate_product_attributes_value;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability_priceRange_start_net {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability_priceRange_start {
+ __typename: "TaxedMoney";
+ net: SimpleProductUpdate_productUpdate_product_availability_priceRange_start_net;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability_priceRange_stop_net {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability_priceRange_stop {
+ __typename: "TaxedMoney";
+ net: SimpleProductUpdate_productUpdate_product_availability_priceRange_stop_net;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability_priceRange {
+ __typename: "TaxedMoneyRange";
+ start: SimpleProductUpdate_productUpdate_product_availability_priceRange_start | null;
+ stop: SimpleProductUpdate_productUpdate_product_availability_priceRange_stop | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_availability {
+ __typename: "ProductAvailability";
+ available: boolean | null;
+ priceRange: SimpleProductUpdate_productUpdate_product_availability_priceRange | null;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_images {
+ __typename: "ProductImage";
+ id: string;
+ alt: string;
+ sortOrder: number;
+ url: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_variants_priceOverride {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_variants {
+ __typename: "ProductVariant";
+ id: string;
+ sku: string;
+ name: string;
+ priceOverride: SimpleProductUpdate_productUpdate_product_variants_priceOverride | null;
+ margin: number | null;
+ quantity: number;
+ quantityAllocated: number;
+ stockQuantity: number;
+}
+
+export interface SimpleProductUpdate_productUpdate_product_productType {
+ __typename: "ProductType";
+ id: string;
+ name: string;
+ hasVariants: boolean;
+}
+
+export interface SimpleProductUpdate_productUpdate_product {
+ __typename: "Product";
+ id: string;
+ name: string;
+ description: string;
+ seoTitle: string | null;
+ seoDescription: string | null;
+ category: SimpleProductUpdate_productUpdate_product_category;
+ collections: (SimpleProductUpdate_productUpdate_product_collections | null)[] | null;
+ price: SimpleProductUpdate_productUpdate_product_price | null;
+ margin: SimpleProductUpdate_productUpdate_product_margin | null;
+ purchaseCost: SimpleProductUpdate_productUpdate_product_purchaseCost | null;
+ isPublished: boolean;
+ chargeTaxes: boolean;
+ availableOn: any | null;
+ attributes: SimpleProductUpdate_productUpdate_product_attributes[];
+ availability: SimpleProductUpdate_productUpdate_product_availability | null;
+ images: (SimpleProductUpdate_productUpdate_product_images | null)[] | null;
+ variants: (SimpleProductUpdate_productUpdate_product_variants | null)[] | null;
+ productType: SimpleProductUpdate_productUpdate_product_productType;
+ url: string;
+}
+
+export interface SimpleProductUpdate_productUpdate {
+ __typename: "ProductUpdate";
+ errors: (SimpleProductUpdate_productUpdate_errors | null)[] | null;
+ product: SimpleProductUpdate_productUpdate_product | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ slug: string | null;
+ values: (SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute_values | null)[] | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes_value {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes {
+ __typename: "SelectedAttribute";
+ attribute: SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute;
+ value: SimpleProductUpdate_productVariantUpdate_productVariant_attributes_value;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_costPrice {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_images {
+ __typename: "ProductImage";
+ id: string;
+ url: string;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_priceOverride {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_product_images {
+ __typename: "ProductImage";
+ id: string;
+ alt: string;
+ sortOrder: number;
+ url: string;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_product_variants_images {
+ __typename: "ProductImage";
+ id: string;
+ url: string;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_product_variants {
+ __typename: "ProductVariant";
+ id: string;
+ name: string;
+ sku: string;
+ images: (SimpleProductUpdate_productVariantUpdate_productVariant_product_variants_images | null)[] | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant_product {
+ __typename: "Product";
+ id: string;
+ images: (SimpleProductUpdate_productVariantUpdate_productVariant_product_images | null)[] | null;
+ name: string;
+ thumbnailUrl: string | null;
+ variants: (SimpleProductUpdate_productVariantUpdate_productVariant_product_variants | null)[] | null;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate_productVariant {
+ __typename: "ProductVariant";
+ id: string;
+ attributes: SimpleProductUpdate_productVariantUpdate_productVariant_attributes[];
+ costPrice: SimpleProductUpdate_productVariantUpdate_productVariant_costPrice | null;
+ images: (SimpleProductUpdate_productVariantUpdate_productVariant_images | null)[] | null;
+ name: string;
+ priceOverride: SimpleProductUpdate_productVariantUpdate_productVariant_priceOverride | null;
+ product: SimpleProductUpdate_productVariantUpdate_productVariant_product;
+ sku: string;
+ quantity: number;
+ quantityAllocated: number;
+}
+
+export interface SimpleProductUpdate_productVariantUpdate {
+ __typename: "ProductVariantUpdate";
+ errors: (SimpleProductUpdate_productVariantUpdate_errors | null)[] | null;
+ productVariant: SimpleProductUpdate_productVariantUpdate_productVariant | null;
+}
+
+export interface SimpleProductUpdate {
+ productUpdate: SimpleProductUpdate_productUpdate | null;
+ productVariantUpdate: SimpleProductUpdate_productVariantUpdate | null;
+}
+
+export interface SimpleProductUpdateVariables {
+ id: string;
+ attributes?: (AttributeValueInput | null)[] | null;
+ availableOn?: any | null;
+ category?: string | null;
+ chargeTaxes: boolean;
+ collections?: (string | null)[] | null;
+ description?: string | null;
+ isPublished: boolean;
+ name?: string | null;
+ price?: any | null;
+ productVariantId: string;
+ productVariantInput: ProductVariantInput;
+}
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
index 0cc199b844..0733dc3836 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
@@ -86,7 +86,8 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
deleteProduct,
deleteProductImage,
reorderProductImages,
- updateProduct
+ updateProduct,
+ updateSimpleProduct
}) => {
const handleImageDelete = (id: string) => () =>
deleteProductImage.mutate({ id });
@@ -96,23 +97,49 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
navigate(productImageUrl(id, imageId));
const handleSubmit = (data: FormData) => {
if (product) {
- updateProduct.mutate({
- attributes: data.attributes,
- availableOn:
- data.availableOn !== ""
- ? data.availableOn
- : null,
- category: data.category.value,
- chargeTaxes: data.chargeTaxes,
- collections: data.collections.map(
- collection => collection.value
- ),
- description: data.description,
- id: product.id,
- isPublished: data.available,
- name: data.name,
- price: decimal(data.price)
- });
+ if (product.productType.hasVariants) {
+ updateProduct.mutate({
+ attributes: data.attributes,
+ availableOn:
+ data.availableOn !== ""
+ ? data.availableOn
+ : null,
+ category: data.category.value,
+ chargeTaxes: data.chargeTaxes,
+ collections: data.collections.map(
+ collection => collection.value
+ ),
+ description: data.description,
+ id: product.id,
+ isPublished: data.available,
+ name: data.name,
+ price: decimal(data.price)
+ });
+ } else {
+ updateSimpleProduct.mutate({
+ attributes: data.attributes,
+ availableOn:
+ data.availableOn !== ""
+ ? data.availableOn
+ : null,
+ category: data.category.value,
+ chargeTaxes: data.chargeTaxes,
+ collections: data.collections.map(
+ collection => collection.value
+ ),
+ description: data.description,
+ id: product.id,
+ isPublished: data.available,
+ name: data.name,
+ price: decimal(data.price),
+ productVariantId:
+ product.variants[0].id,
+ productVariantInput: {
+ quantity: data.stockQuantity,
+ sku: data.sku
+ }
+ });
+ }
}
};
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index 74f14889bf..c1980474e4 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -268,6 +268,16 @@ export interface ProductTypeInput {
taxRate?: TaxRateType | null;
}
+export interface ProductVariantInput {
+ attributes?: (AttributeValueInput | null)[] | null;
+ costPrice?: any | null;
+ priceOverride?: any | null;
+ sku?: string | null;
+ quantity?: number | null;
+ trackInventory?: boolean | null;
+ weight?: any | null;
+}
+
export interface SeoInput {
title?: string | null;
description?: string | null;