Add store-item bulk create, unlimited stock, and contact-for-price UI.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
5eaf7fb046
commit
ad83fc1099
@@ -1,4 +1,5 @@
|
||||
import type { ProductVariationSelection } from '../services/productVariationService'
|
||||
import type { CreateStoreItemPayload } from '../services/storeItemService'
|
||||
import { createId } from './id'
|
||||
|
||||
export interface StoreItemDraftRow {
|
||||
@@ -7,8 +8,13 @@ export interface StoreItemDraftRow {
|
||||
selections: Record<string, string>
|
||||
price: string
|
||||
stock: string
|
||||
/** When true, stockQuantity is sent as null (unlimited). */
|
||||
unlimitedStock: boolean
|
||||
}
|
||||
|
||||
/** Bulk-create: only first variation, at most this many options. */
|
||||
export const BULK_CREATE_MAX_OPTIONS = 5
|
||||
|
||||
export function getVariationOptions(variation: ProductVariationSelection) {
|
||||
if (variation.selectedOptionIds.length > 0) {
|
||||
return variation.options.filter((option) =>
|
||||
@@ -24,5 +30,28 @@ export function createEmptyStoreItemRow(): StoreItemDraftRow {
|
||||
selections: {},
|
||||
price: '',
|
||||
stock: '1',
|
||||
unlimitedStock: false,
|
||||
}
|
||||
}
|
||||
|
||||
/** Build create payloads for bulk “add all products” (price null, stock 0). */
|
||||
export function buildBulkCreateItems(
|
||||
variations: ProductVariationSelection[],
|
||||
): CreateStoreItemPayload[] {
|
||||
const withOptions = variations.filter(
|
||||
(variation) => getVariationOptions(variation).length > 0,
|
||||
)
|
||||
|
||||
if (withOptions.length === 0) {
|
||||
return [{ selections: [], price: null, stockQuantity: 0 }]
|
||||
}
|
||||
|
||||
const first = withOptions[0]!
|
||||
const options = getVariationOptions(first).slice(0, BULK_CREATE_MAX_OPTIONS)
|
||||
|
||||
return options.map((option) => ({
|
||||
selections: [{ variationId: first.id, optionId: option.id }],
|
||||
price: null,
|
||||
stockQuantity: 0,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user