feat: Update the product options model and refactor the product module (#6685)
The changes in this PR are: 1. Change how product options are created and stored. The relationship changed from `options --> option values <-- variants` to `options --> option values --> variant options <-- variants` Now we can enforce non-duplicate option values, easier creation and updates of options, and more. 2. Refactors the product module. The product module did a lot of things in a non-ideal approach, and this is a step towards a more consistent usage of the base repository and methods exposed by a module. There is still work left to improve the module, but a large chunk of the changes are included in this PR Things to do as a follow-up: 1. Remove many-to-many relationships if an empty list is passed in the base repository. 2. Improve the typings of the module 3. Further cleanup and improvements (there are few questions that I need answered before I can improve the API)
This commit is contained in:
@@ -229,7 +229,7 @@ export interface ProductVariantDTO {
|
||||
*
|
||||
* @expandable
|
||||
*/
|
||||
options: ProductOptionValueDTO[]
|
||||
options: ProductVariantOptionDTO[]
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
@@ -511,6 +511,25 @@ export interface ProductOptionDTO {
|
||||
deleted_at?: string | Date
|
||||
}
|
||||
|
||||
export interface ProductVariantOptionDTO {
|
||||
/**
|
||||
* The ID of the product variant option.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The value of the product variant option.
|
||||
*
|
||||
* @expandable
|
||||
*/
|
||||
option_value: ProductOptionValueDTO
|
||||
/**
|
||||
* The associated product variant.
|
||||
*
|
||||
* @expandable
|
||||
*/
|
||||
variant: ProductVariantDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
@@ -567,12 +586,6 @@ export interface ProductOptionValueDTO {
|
||||
* @expandable
|
||||
*/
|
||||
option: ProductOptionDTO
|
||||
/**
|
||||
* The associated product variant.
|
||||
*
|
||||
* @expandable
|
||||
*/
|
||||
variant: ProductVariantDTO
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
@@ -732,7 +745,7 @@ export interface FilterableProductOptionProps
|
||||
/**
|
||||
* The titles to filter product options by.
|
||||
*/
|
||||
title?: string
|
||||
title?: string | string[]
|
||||
/**
|
||||
* Filter the product options by their associated products' IDs.
|
||||
*/
|
||||
@@ -790,12 +803,7 @@ export interface FilterableProductVariantProps
|
||||
/**
|
||||
* Filter product variants by their associated options.
|
||||
*/
|
||||
options?: {
|
||||
/**
|
||||
* IDs to filter options by.
|
||||
*/
|
||||
id?: string[]
|
||||
}
|
||||
options?: Record<string, string>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1000,6 +1008,10 @@ export interface CreateProductOptionDTO {
|
||||
* The product option's title.
|
||||
*/
|
||||
title: string
|
||||
/**
|
||||
* The product option values.
|
||||
*/
|
||||
values: string[] | { value: string }[]
|
||||
/**
|
||||
* The ID of the associated product.
|
||||
*/
|
||||
@@ -1009,23 +1021,10 @@ export interface CreateProductOptionDTO {
|
||||
export interface UpdateProductOptionDTO {
|
||||
id: string
|
||||
title?: string
|
||||
values?: string[] | { value: string }[]
|
||||
product_id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* A product variant option to create.
|
||||
*/
|
||||
export interface CreateProductVariantOptionDTO {
|
||||
/**
|
||||
* The value of a product variant option.
|
||||
*/
|
||||
value: string
|
||||
|
||||
option_id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
@@ -1101,9 +1100,9 @@ export interface CreateProductVariantDTO {
|
||||
*/
|
||||
width?: number
|
||||
/**
|
||||
* The product variant options to create and associate with the product variant.
|
||||
* The product variant options to associate with the product variant.
|
||||
*/
|
||||
options?: CreateProductVariantOptionDTO[]
|
||||
options?: Record<string, string>
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
@@ -1193,9 +1192,9 @@ export interface UpdateProductVariantDTO {
|
||||
*/
|
||||
width?: number
|
||||
/**
|
||||
* The product variant options to create and associate with the product variant.
|
||||
* The product variant options to associate with the product variant.
|
||||
*/
|
||||
options?: CreateProductVariantOptionDTO[]
|
||||
options?: Record<string, string>
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
@@ -1428,78 +1427,3 @@ export interface UpdateProductDTO {
|
||||
*/
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface CreateProductOnlyDTO {
|
||||
title: string
|
||||
subtitle?: string
|
||||
description?: string
|
||||
is_giftcard?: boolean
|
||||
discountable?: boolean
|
||||
images?: { id?: string; url: string }[]
|
||||
thumbnail?: string
|
||||
handle?: string
|
||||
status?: ProductStatus
|
||||
collection_id?: string
|
||||
width?: number
|
||||
height?: number
|
||||
length?: number
|
||||
weight?: number
|
||||
origin_country?: string
|
||||
hs_code?: string
|
||||
material?: string
|
||||
mid_code?: string
|
||||
metadata?: Record<string, unknown>
|
||||
tags?: { id: string }[]
|
||||
categories?: { id: string }[]
|
||||
type_id?: string
|
||||
}
|
||||
|
||||
export interface CreateProductVariantOnlyDTO {
|
||||
product_id?: string
|
||||
title: string
|
||||
sku?: string
|
||||
barcode?: string
|
||||
ean?: string
|
||||
upc?: string
|
||||
allow_backorder?: boolean
|
||||
inventory_quantity?: number
|
||||
manage_inventory?: boolean
|
||||
hs_code?: string
|
||||
origin_country?: string
|
||||
mid_code?: string
|
||||
material?: string
|
||||
weight?: number
|
||||
length?: number
|
||||
height?: number
|
||||
width?: number
|
||||
options?: (CreateProductVariantOptionDTO & { option: any })[]
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface UpdateProductVariantOnlyDTO {
|
||||
id: string
|
||||
title?: string
|
||||
sku?: string
|
||||
barcode?: string
|
||||
ean?: string
|
||||
upc?: string
|
||||
allow_backorder?: boolean
|
||||
inventory_quantity?: number
|
||||
manage_inventory?: boolean
|
||||
hs_code?: string
|
||||
origin_country?: string
|
||||
mid_code?: string
|
||||
material?: string
|
||||
weight?: number
|
||||
length?: number
|
||||
height?: number
|
||||
width?: number
|
||||
options?: (CreateProductVariantOptionDTO & { option: any })[]
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface CreateProductOptionOnlyDTO {
|
||||
product_id?: string
|
||||
product?: Record<any, any>
|
||||
title: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user