|
@@ -36,6 +36,7 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
customFields: CustomFieldConfig[];
|
|
customFields: CustomFieldConfig[];
|
|
|
customVariantFields: CustomFieldConfig[];
|
|
customVariantFields: CustomFieldConfig[];
|
|
|
productForm: FormGroup;
|
|
productForm: FormGroup;
|
|
|
|
|
+ assetChanges: { assetIds?: string[]; featuredAssetId?: string } = {};
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
route: ActivatedRoute,
|
|
route: ActivatedRoute,
|
|
@@ -79,6 +80,10 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
return !!this.productForm.get(['product', 'customFields', name]);
|
|
return !!this.productForm.get(['product', 'customFields', name]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ assetsChanged(): boolean {
|
|
|
|
|
+ return !!Object.values(this.assetChanges).length;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* If creating a new product, automatically generate the slug based on the product name.
|
|
* If creating a new product, automatically generate the slug based on the product name.
|
|
|
*/
|
|
*/
|
|
@@ -137,6 +142,7 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
this.notificationService.success(_('common.notify-create-success'), {
|
|
this.notificationService.success(_('common.notify-create-success'), {
|
|
|
entity: 'Product',
|
|
entity: 'Product',
|
|
|
});
|
|
});
|
|
|
|
|
+ this.assetChanges = {};
|
|
|
this.productForm.markAsPristine();
|
|
this.productForm.markAsPristine();
|
|
|
this.router.navigate(['../', data.createProduct.id], { relativeTo: this.route });
|
|
this.router.navigate(['../', data.createProduct.id], { relativeTo: this.route });
|
|
|
},
|
|
},
|
|
@@ -157,7 +163,7 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
const productGroup = this.productForm.get('product');
|
|
const productGroup = this.productForm.get('product');
|
|
|
const updateOperations: Array<Observable<any>> = [];
|
|
const updateOperations: Array<Observable<any>> = [];
|
|
|
|
|
|
|
|
- if (productGroup && productGroup.dirty) {
|
|
|
|
|
|
|
+ if ((productGroup && productGroup.dirty) || this.assetsChanged()) {
|
|
|
const newProduct = this.getUpdatedProduct(
|
|
const newProduct = this.getUpdatedProduct(
|
|
|
product,
|
|
product,
|
|
|
productGroup as FormGroup,
|
|
productGroup as FormGroup,
|
|
@@ -183,6 +189,7 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
.subscribe(
|
|
.subscribe(
|
|
|
() => {
|
|
() => {
|
|
|
this.productForm.markAsPristine();
|
|
this.productForm.markAsPristine();
|
|
|
|
|
+ this.assetChanges = {};
|
|
|
this.notificationService.success(_('common.notify-update-success'), {
|
|
this.notificationService.success(_('common.notify-update-success'), {
|
|
|
entity: 'Product',
|
|
entity: 'Product',
|
|
|
});
|
|
});
|
|
@@ -255,12 +262,19 @@ export class ProductDetailComponent extends BaseDetailComponent<ProductWithVaria
|
|
|
productFormGroup: FormGroup,
|
|
productFormGroup: FormGroup,
|
|
|
languageCode: LanguageCode,
|
|
languageCode: LanguageCode,
|
|
|
): UpdateProductInput | CreateProductInput {
|
|
): UpdateProductInput | CreateProductInput {
|
|
|
- return createUpdatedTranslatable(product, productFormGroup.value, this.customFields, languageCode, {
|
|
|
|
|
|
|
+ const updatedProduct = createUpdatedTranslatable(
|
|
|
|
|
+ product,
|
|
|
|
|
+ productFormGroup.value,
|
|
|
|
|
+ this.customFields,
|
|
|
languageCode,
|
|
languageCode,
|
|
|
- name: product.name || '',
|
|
|
|
|
- slug: product.slug || '',
|
|
|
|
|
- description: product.description || '',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ languageCode,
|
|
|
|
|
+ name: product.name || '',
|
|
|
|
|
+ slug: product.slug || '',
|
|
|
|
|
+ description: product.description || '',
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+ return { ...updatedProduct, ...this.assetChanges } as UpdateProductInput | CreateProductInput;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|