Product variations should inherit parent product properties (#36234)

Remove manage_stock 'parent' value before saving the variation
This commit is contained in:
Maikel David Pérez Gómez 2023-01-11 11:41:25 -03:00 committed by GitHub
parent ef3d15fcd4
commit 8bada412d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add manage_stock parent value to product variation type definition

View File

@ -55,13 +55,21 @@ export interface ProductVariationImage {
export type ProductVariation = Omit<
Product,
'name' | 'slug' | 'attributes' | 'images'
'name' | 'slug' | 'attributes' | 'images' | 'manage_stock'
> & {
attributes: ProductVariationAttribute[];
/**
* Variation image data.
*/
image?: ProductVariationImage;
/**
* Stock management at variation level. It can have a
* 'parent' value if the parent product is managing
* the stock at the time the variation was created.
*
* @default false
*/
manage_stock: boolean | 'parent';
};
type Query = Omit< ProductQuery, 'name' >;

View File

@ -36,8 +36,14 @@ export const ProductVariationFormActions: React.FC = () => {
const onSave = async () => {
setIsSaving( true );
updateProductVariation< Promise< ProductVariation > >(
{ id: variationId, product_id: productId },
values
{ id: variationId, product_id: productId, context: 'edit' },
{
...values,
manage_stock:
values.manage_stock === 'parent'
? undefined
: values?.manage_stock,
}
)
.then( () => {
createNotice(

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Remove manage_stock 'parent' value before saving the variation