Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features for adding/editing product and its variant. #63

Merged
merged 20 commits into from
Aug 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: edit product variant for physical goods
belsman committed Aug 21, 2024
commit 1f4a89fdf5ed5950e81005952d7fee9c0549ca89
4 changes: 2 additions & 2 deletions packages/core/graphql/src/lib/documents/fragments/product.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fragment ProductFragment on IoRestorecommerceProductProduct {
id
tags
# tags
product {
name
description
@@ -28,7 +28,7 @@ fragment ProductFragment on IoRestorecommerceProductProduct {
# }
stockLevel
stockKeepingUnit
parentVariantId
# parentVariantId
taxIds
price {
currencyId
14 changes: 0 additions & 14 deletions packages/core/graphql/src/lib/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -5411,7 +5411,6 @@ export type CatalogProductMutateMutation = {
payload?: {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -5432,7 +5431,6 @@ export type CatalogProductMutateMutation = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -5508,7 +5506,6 @@ export type CatalogProductReadQuery = {
payload?: {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -5529,7 +5526,6 @@ export type CatalogProductReadQuery = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -5981,7 +5977,6 @@ export type OrderFragmentFragment = {
product?: {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -6002,7 +5997,6 @@ export type OrderFragmentFragment = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -6519,7 +6513,6 @@ export type OrganizationFragmentFragment = {
export type ProductFragmentFragment = {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -6540,7 +6533,6 @@ export type ProductFragmentFragment = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -8244,7 +8236,6 @@ export type OrderingOrderMutateMutation = {
product?: {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -8265,7 +8256,6 @@ export type OrderingOrderMutateMutation = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -8782,7 +8772,6 @@ export type OrderingOrderReadQuery = {
product?: {
__typename?: 'IoRestorecommerceProductProduct';
id?: string | null;
tags?: Array<string> | null;
product?: {
__typename?: 'IoRestorecommerceProductIndividualProduct';
name?: string | null;
@@ -8803,7 +8792,6 @@ export type OrderingOrderReadQuery = {
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
@@ -9393,7 +9381,6 @@ export const LocationFragmentFragmentDoc = gql`
export const ProductFragmentFragmentDoc = gql`
fragment ProductFragment on IoRestorecommerceProductProduct {
id
tags
product {
name
description
@@ -9411,7 +9398,6 @@ export const ProductFragmentFragmentDoc = gql`
description
stockLevel
stockKeepingUnit
parentVariantId
taxIds
price {
currencyId
Original file line number Diff line number Diff line change
@@ -69,13 +69,57 @@ export class ProductVariantEditComponent {
}

onSubmit() {
// ASSUME A PRODUCT IS PHYSICAL!
const value = this.variantModalForm.form.value as IProductVariantFormValue;
value.id = uuidv4();

if (value.offerings === 'physical') {
// REMOVE the field 'offerings'
delete value.offerings;
// Fix the backend price issues!
const regularPrice = +(value.price?.regularPrice || 0);
const salePrice = +(value.price?.salePrice || 0);

// TODO Convert price!
value.stockLevel = +(value.stockLevel || 0);
value.price = {
...value.price,
regularPrice,
salePrice,
};

// REMOVE the field 'offerings'
delete value.offerings;

if (this.variant.id) {
// EDIT MODE
const updatedVariant: IIoRestorecommerceProductPhysicalVariant = {
...this.variant,
...value,
};

const productWithUpdatedVariant =
this.product.product.physical?.variants?.map((variant) => {
if (variant.id === updatedVariant.id) {
return updatedVariant;
} else {
return variant;
}
});

const product: IProduct = {
...this.product,
product: {
...this.product.product,
physical: {
variants: productWithUpdatedVariant,
},
},
};

this.productFacade.update({
items: [product],
mode: ModeType.Update,
});
} else {
// CREATE MODE
value.id = uuidv4();
let product: IProduct;

if (this.product.product.physical?.variants) {
@@ -116,10 +160,9 @@ export class ProductVariantEditComponent {
}

this.close();
// Massage the value to the parent product
}

onAction(_: string) {
// TODO
this.close();
}
}
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import { ProductVariantEditComponent } from './product-variant-modal.component';
<ng-container *ngIf="vm$ | async as vm">
<rc-product-view
(addVariant)="onAddVariant(vm.product)"
(editVariant)="onEditVariant($event)"
(editVariant)="onEditVariant($event, vm.product)"
[product]="vm.product"
/>
</ng-container>
@@ -93,12 +93,15 @@ export class ProductViewComponent implements OnInit, OnDestroy {
.subscribe();
}

onEditVariant(variant: IIoRestorecommerceProductPhysicalVariant) {
console.log('variant:', variant);
onEditVariant(
variant: IIoRestorecommerceProductPhysicalVariant,
product: IProduct
) {
this.subscriptions.sink = this.addVariantLayer
.open({
data: {
title: `Edit product variant`,
product,
variant,
},
})
Original file line number Diff line number Diff line change
@@ -15,13 +15,6 @@ export const buildProductVariantSchema = (
return {
type: 'form',
fields: [
// {
// name: 'price',
// type: 'object',
// fields: [

// ],
// },
{
name: 'offerings',
label: 'Offerings',