Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Refuse a fractional quantity rule instead of truncating it
Damian Legawiec7b46da9e7f58
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.jsonindex 981598d792..f62c9041b5 100644--- a/packages/dashboard-core/src/locales/ar.json+++ b/packages/dashboard-core/src/locales/ar.json@@ -814,7 +814,7 @@"order_multiple": {"label": "مضاعف الطلب","placeholder": "بلا مضاعف",- "help": "يجب أن تكون الطلبات من مضاعفات هذا الرقم. اتركه فارغًا للسماح بأي كمية."+ "help": "كل زيادة فوق الحد الأدنى. اتركه فارغًا للسماح بأي كمية."},"purchase_unit": {"label": "وحدة الشراء",@@ -834,7 +834,7 @@},"order_multiple": {"label": "مضاعف الطلب",- "help": "يجب أن تكون الطلبات من مضاعفات هذا الرقم. اتركه فارغًا للسماح بأي كمية."+ "help": "كل زيادة فوق الحد الأدنى. اتركه فارغًا للسماح بأي كمية."}},"image_upload": {@@ -1553,7 +1553,7 @@"catalogs": {"terms": {"title": "الشروط التجارية",- "description": "الكمية التي يجب على المشترين ضمن هذه الاتفاقية طلبها.",+ "description": "الكميات التي يجب على المشترين ضمن هذه الاتفاقية طلبها.","no_rule_placeholder": "بلا قاعدة","minimums_title": "الحدود الدنيا للطلب","minimums_description": "أقل قيمة يجب أن يبلغها الطلب بالكامل، لكل عملة.",diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.jsonindex 553e901259..997e048dbe 100644--- a/packages/dashboard-core/src/locales/de.json+++ b/packages/dashboard-core/src/locales/de.json@@ -814,7 +814,7 @@"order_multiple": {"label": "Bestellvielfaches","placeholder": "Kein Vielfaches",- "help": "Bestellungen müssen ein Vielfaches davon sein. Leer lassen für beliebige Mengen."+ "help": "Jeder Schritt über der Mindestmenge. Leer lassen für beliebige Mengen."},"purchase_unit": {"label": "Verkaufseinheit",@@ -834,7 +834,7 @@},"order_multiple": {"label": "Bestellvielfaches",- "help": "Bestellungen müssen ein Vielfaches davon sein. Leer lassen für beliebige Mengen."+ "help": "Jeder Schritt über der Mindestmenge. Leer lassen für beliebige Mengen."}},"image_upload": {@@ -1548,7 +1548,7 @@"catalogs": {"terms": {"title": "Handelsbedingungen",- "description": "Wie viel Käufer dieser Vereinbarung bestellen müssen.",+ "description": "Welche Menge Käufer im Rahmen dieser Vereinbarung bestellen müssen.","no_rule_placeholder": "Keine Regel","minimums_title": "Mindestbestellwerte","minimums_description": "Der Mindestwert einer gesamten Bestellung, je Währung.",diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.jsonindex 175d4d7d1f..644623d4ea 100644--- a/packages/dashboard-core/src/locales/en.json+++ b/packages/dashboard-core/src/locales/en.json@@ -816,7 +816,7 @@"order_multiple": {"label": "Order multiple","placeholder": "No multiple",- "help": "Orders must be a multiple of this. Leave blank for any quantity."+ "help": "Each step up from the minimum. Leave blank for any quantity."},"purchase_unit": {"label": "Purchase unit",@@ -836,7 +836,7 @@},"order_multiple": {"label": "Order multiple",- "help": "Orders must be a multiple of this. Leave blank for any quantity."+ "help": "Each step up from the minimum. Leave blank for any quantity."}},"image_upload": {diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.jsonindex 60e84ff01d..57da8e6806 100644--- a/packages/dashboard-core/src/locales/fr.json+++ b/packages/dashboard-core/src/locales/fr.json@@ -814,7 +814,7 @@"order_multiple": {"label": "Multiple de commande","placeholder": "Aucun multiple",- "help": "Les commandes doivent être un multiple de cette valeur. Laisser vide pour toute quantité."+ "help": "Chaque palier au-dessus du minimum. Laisser vide pour toute quantité."},"purchase_unit": {"label": "Unité de vente",@@ -834,7 +834,7 @@},"order_multiple": {"label": "Multiple de commande",- "help": "Les commandes doivent être un multiple de cette valeur. Laisser vide pour toute quantité."+ "help": "Chaque palier au-dessus du minimum. Laisser vide pour toute quantité."}},"image_upload": {@@ -1548,7 +1548,7 @@"catalogs": {"terms": {"title": "Conditions commerciales",- "description": "Combien les acheteurs de cet accord doivent commander.",+ "description": "Les quantités que les acheteurs de cet accord doivent commander.","no_rule_placeholder": "Aucune règle","minimums_title": "Minimums de commande","minimums_description": "Le montant minimal d'une commande entière, par devise.",diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.jsonindex 14f8f93b0d..1e899546e1 100644--- a/packages/dashboard-core/src/locales/pl.json+++ b/packages/dashboard-core/src/locales/pl.json@@ -814,7 +814,7 @@"order_multiple": {"label": "Wielokrotność zamówienia","placeholder": "Brak wielokrotności",- "help": "Zamówienia muszą być wielokrotnością tej liczby. Pozostaw puste, aby dopuścić dowolną ilość."+ "help": "Każdy kolejny krok powyżej minimum. Pozostaw puste, aby dopuścić dowolną ilość."},"purchase_unit": {"label": "Jednostka sprzedaży",@@ -834,7 +834,7 @@},"order_multiple": {"label": "Wielokrotność zamówienia",- "help": "Zamówienia muszą być wielokrotnością tej liczby. Pozostaw puste, aby dopuścić dowolną ilość."+ "help": "Każdy kolejny krok powyżej minimum. Pozostaw puste, aby dopuścić dowolną ilość."}},"image_upload": {@@ -1574,7 +1574,7 @@"catalogs": {"terms": {"title": "Warunki handlowe",- "description": "Ile muszą zamawiać kupujący objęci tą umową.",+ "description": "Jakie ilości muszą zamawiać kupujący objęci tą umową.","no_rule_placeholder": "Brak reguły","minimums_title": "Minimalne wartości zamówienia","minimums_description": "Najniższa wartość całego zamówienia, dla każdej waluty.",diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.jsonindex 8d741cfdf3..40d83e198d 100644--- a/packages/dashboard-core/src/locales/zh-CN.json+++ b/packages/dashboard-core/src/locales/zh-CN.json@@ -814,7 +814,7 @@"order_multiple": {"label": "订购倍数","placeholder": "无倍数",- "help": "订单数量必须是该数值的倍数。留空表示不限数量。"+ "help": "在最小起订量之上的每一档增量。留空表示不限数量。"},"purchase_unit": {"label": "销售单位",@@ -834,7 +834,7 @@},"order_multiple": {"label": "订购倍数",- "help": "订单数量必须是该数值的倍数。留空表示不限数量。"+ "help": "在最小起订量之上的每一档增量。留空表示不限数量。"}},"image_upload": {@@ -1547,7 +1547,7 @@"catalogs": {"terms": {"title": "商务条款",- "description": "适用本协议的买家必须订购多少。",+ "description": "适用本协议的买家必须订购的数量。","no_rule_placeholder": "无规则","minimums_title": "订单最低金额","minimums_description": "整笔订单必须达到的最低金额,按币种设置。",diff --git a/packages/dashboard-core/src/products/normalize-quantity.test.ts b/packages/dashboard-core/src/products/normalize-quantity.test.tsindex 316399a311..058e574335 100644--- a/packages/dashboard-core/src/products/normalize-quantity.test.ts+++ b/packages/dashboard-core/src/products/normalize-quantity.test.ts@@ -22,7 +22,11 @@ describe('normalizeQuantityRule', () => {expect(normalizeQuantityRule('abc')).toBeNull()})- it('truncates a fractional entry to whole units', () => {- expect(normalizeQuantityRule('48.9')).toBe(48)+ // Truncating would be the same silent adjustment the whole feature exists+ // to prevent, one level up.+ it('refuses a fraction rather than truncating it', () => {+ expect(normalizeQuantityRule('48.9')).toBeNull()+ expect(normalizeQuantityRule('2.5')).toBeNull()+ expect(normalizeQuantityRule(1.5)).toBeNull()})})diff --git a/packages/dashboard-core/src/products/normalize-quantity.ts b/packages/dashboard-core/src/products/normalize-quantity.tsindex 0388f8317d..1be4f0385f 100644--- a/packages/dashboard-core/src/products/normalize-quantity.ts+++ b/packages/dashboard-core/src/products/normalize-quantity.ts@@ -12,14 +12,20 @@ export type PurchaseUnit = (typeof PURCHASE_UNITS)[number]* which is not the same as zero: an empty minimum lets a buyer take one, a* minimum of zero is meaningless and the server refuses it.*- * @returns a positive whole number, or null when the field says nothing.+ * A fraction is refused rather than truncated. These rules are whole units,+ * and this feature exists because silently adjusting a wholesale quantity is+ * a five-figure surprise — a rule of 2.5 saved as 2 is the same mistake one+ * level up.+ *+ * @returns a positive whole number, or null when the field says nothing or+ * cannot be one.*/export function normalizeQuantityRule(value: unknown): number | null {const trimmed = String(value ?? '').trim()if (trimmed === '') return nullconst parsed = Number(trimmed)- if (!Number.isFinite(parsed) || parsed < 1) return null+ if (!Number.isInteger(parsed) || parsed < 1) return null- return Math.trunc(parsed)+ return parsed}diff --git a/packages/dashboard/src/components/spree/catalog-terms-card.tsx b/packages/dashboard/src/components/spree/catalog-terms-card.tsxindex 6f50c5fbbd..af26eddda5 100644--- a/packages/dashboard/src/components/spree/catalog-terms-card.tsx+++ b/packages/dashboard/src/components/spree/catalog-terms-card.tsx@@ -426,11 +426,16 @@ function AddQuantityRuleDialog({const [multiple, setMultiple] = useState('')// A row must state at least one field: an override that overrides nothing- // is a half-filled form, and the server refuses it anyway.+ // is a half-filled form, and the server refuses it anyway. Each stated+ // field must also be usable — without checking here the request goes,+ // fails validation, and the dialog just sits there saying nothing.+ const minimumValid = !minimum.trim() || normalizeQuantityRule(minimum) !== null+ const multipleValid = !multiple.trim() || normalizeQuantityRule(multiple) !== nullconst statesSomething = !!minimum.trim() || !!multiple.trim()+ const canSubmit = statesSomething && minimumValid && multipleValidasync function handleSubmit() {- if (!variantId || !statesSomething) return+ if (!variantId || !canSubmit) returnawait createMutation.mutateAsync({@@ -483,9 +488,13 @@ function AddQuantityRuleDialog({type="number"min={1}step={1}+ aria-invalid={!minimumValid}value={minimum}onChange={(event) => setMinimum(event.target.value)}/>+ {!minimumValid && (+ <FieldError>{t('admin.catalogs.terms.validation.positive_integer')}</FieldError>+ )}</Field><Field><FieldLabel htmlFor="rule-multiple">@@ -496,9 +505,13 @@ function AddQuantityRuleDialog({type="number"min={1}step={1}+ aria-invalid={!multipleValid}value={multiple}onChange={(event) => setMultiple(event.target.value)}/>+ {!multipleValid && (+ <FieldError>{t('admin.catalogs.terms.validation.positive_integer')}</FieldError>+ )}<FieldDescription>{t('admin.catalogs.terms.override_help')}</FieldDescription></Field></FieldGroup>@@ -509,7 +522,7 @@ function AddQuantityRuleDialog({</Button><Buttontype="button"- disabled={createMutation.isPending || !variantId || !statesSomething}+ disabled={createMutation.isPending || !variantId || !canSubmit}onClick={handleSubmit}>{t('admin.actions.add')}diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex 6f2cacf16a..df709f1f41 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -159,7 +159,7 @@"search_placeholder": "البحث في الكتالوجات","terms": {"title": "الشروط التجارية",- "description": "الكمية التي يجب على المشترين ضمن هذه الاتفاقية طلبها.",+ "description": "الكميات التي يجب على المشترين ضمن هذه الاتفاقية طلبها.","no_rule_placeholder": "بلا قاعدة","minimums_title": "الحدود الدنيا للطلب","minimums_description": "أقل قيمة يجب أن يبلغها الطلب بالكامل، لكل عملة.",@@ -2173,7 +2173,7 @@"order_multiple": {"label": "مضاعف الطلب","placeholder": "بلا مضاعف",- "help": "يجب أن تكون الطلبات من مضاعفات هذا الرقم. اتركه فارغًا للسماح بأي كمية."+ "help": "كل زيادة فوق الحد الأدنى. اتركه فارغًا للسماح بأي كمية."},"purchase_unit": {"label": "وحدة الشراء",@@ -2212,7 +2212,7 @@},"order_multiple": {"label": "مضاعف الطلب",- "help": "يجب أن تكون الطلبات من مضاعفات هذا الرقم. اتركه فارغًا للسماح بأي كمية."+ "help": "كل زيادة فوق الحد الأدنى. اتركه فارغًا للسماح بأي كمية."}},"gift_cards": {diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex a36806f53f..a60e41667b 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -159,7 +159,7 @@"search_placeholder": "Kataloge suchen","terms": {"title": "Handelsbedingungen",- "description": "Wie viel Käufer dieser Vereinbarung bestellen müssen.",+ "description": "Welche Menge Käufer im Rahmen dieser Vereinbarung bestellen müssen.","no_rule_placeholder": "Keine Regel","minimums_title": "Mindestbestellwerte","minimums_description": "Der Mindestwert einer gesamten Bestellung, je Währung.",@@ -2159,7 +2159,7 @@"order_multiple": {"label": "Bestellvielfaches","placeholder": "Kein Vielfaches",- "help": "Bestellungen müssen ein Vielfaches davon sein. Leer lassen für beliebige Mengen."+ "help": "Jeder Schritt über der Mindestmenge. Leer lassen für beliebige Mengen."},"purchase_unit": {"label": "Verkaufseinheit",@@ -2198,7 +2198,7 @@},"order_multiple": {"label": "Bestellvielfaches",- "help": "Bestellungen müssen ein Vielfaches davon sein. Leer lassen für beliebige Mengen."+ "help": "Jeder Schritt über der Mindestmenge. Leer lassen für beliebige Mengen."}},"gift_cards": {diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex ad54ecb7ab..0c19469394 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -2159,7 +2159,7 @@"order_multiple": {"label": "Order multiple","placeholder": "No multiple",- "help": "Orders must be a multiple of this. Leave blank for any quantity."+ "help": "Each step up from the minimum. Leave blank for any quantity."},"purchase_unit": {"label": "Purchase unit",@@ -2198,7 +2198,7 @@},"order_multiple": {"label": "Order multiple",- "help": "Orders must be a multiple of this. Leave blank for any quantity."+ "help": "Each step up from the minimum. Leave blank for any quantity."}},"gift_cards": {diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex c50fc2605d..ee6131b6ce 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -159,7 +159,7 @@"search_placeholder": "Rechercher des catalogues","terms": {"title": "Conditions commerciales",- "description": "Combien les acheteurs de cet accord doivent commander.",+ "description": "Les quantités que les acheteurs de cet accord doivent commander.","no_rule_placeholder": "Aucune règle","minimums_title": "Minimums de commande","minimums_description": "Le montant minimal d'une commande entière, par devise.",@@ -2159,7 +2159,7 @@"order_multiple": {"label": "Multiple de commande","placeholder": "Aucun multiple",- "help": "Les commandes doivent être un multiple de cette valeur. Laisser vide pour toute quantité."+ "help": "Chaque palier au-dessus du minimum. Laisser vide pour toute quantité."},"purchase_unit": {"label": "Unité de vente",@@ -2198,7 +2198,7 @@},"order_multiple": {"label": "Multiple de commande",- "help": "Les commandes doivent être un multiple de cette valeur. Laisser vide pour toute quantité."+ "help": "Chaque palier au-dessus du minimum. Laisser vide pour toute quantité."}},"gift_cards": {diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex 01b470762f..9609fc1a9d 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -161,7 +161,7 @@"search_placeholder": "Szukaj katalogów","terms": {"title": "Warunki handlowe",- "description": "Ile muszą zamawiać kupujący objęci tą umową.",+ "description": "Jakie ilości muszą zamawiać kupujący objęci tą umową.","no_rule_placeholder": "Brak reguły","minimums_title": "Minimalne wartości zamówienia","minimums_description": "Najniższa wartość całego zamówienia, dla każdej waluty.",@@ -2171,7 +2171,7 @@"order_multiple": {"label": "Wielokrotność zamówienia","placeholder": "Brak wielokrotności",- "help": "Zamówienia muszą być wielokrotnością tej liczby. Pozostaw puste, aby dopuścić dowolną ilość."+ "help": "Każdy kolejny krok powyżej minimum. Pozostaw puste, aby dopuścić dowolną ilość."},"purchase_unit": {"label": "Jednostka sprzedaży",@@ -2210,7 +2210,7 @@},"order_multiple": {"label": "Wielokrotność zamówienia",- "help": "Zamówienia muszą być wielokrotnością tej liczby. Pozostaw puste, aby dopuścić dowolną ilość."+ "help": "Każdy kolejny krok powyżej minimum. Pozostaw puste, aby dopuścić dowolną ilość."}},"gift_cards": {diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex c156faf7f3..51179bb668 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -159,7 +159,7 @@"search_placeholder": "搜索目录","terms": {"title": "商务条款",- "description": "适用本协议的买家必须订购多少。",+ "description": "适用本协议的买家必须订购的数量。","no_rule_placeholder": "无规则","minimums_title": "订单最低金额","minimums_description": "整笔订单必须达到的最低金额,按币种设置。",@@ -2155,7 +2155,7 @@"order_multiple": {"label": "订购倍数","placeholder": "无倍数",- "help": "订单数量必须是该数值的倍数。留空表示不限数量。"+ "help": "在最小起订量之上的每一档增量。留空表示不限数量。"},"purchase_unit": {"label": "销售单位",@@ -2194,7 +2194,7 @@},"order_multiple": {"label": "订购倍数",- "help": "订单数量必须是该数值的倍数。留空表示不限数量。"+ "help": "在最小起订量之上的每一档增量。留空表示不限数量。"}},"gift_cards": {