Pārlūkot izejas kodu

fix(core): Fix edge case for custom field comparison on MySQL

Relates to #1612
Michael Bromley 3 gadi atpakaļ
vecāks
revīzija
f08f62cdb8

+ 7 - 1
packages/core/src/service/helpers/order-modifier/order-modifier.ts

@@ -603,7 +603,13 @@ export class OrderModifier {
 
         for (const def of customFieldDefs) {
             const key = def.name;
-            const existingValue = existingCustomFields?.[key];
+            // This ternary is there because with the MySQL driver, boolean customFields with a default
+            // of `false` were being rep-resented as `0`, thus causing the equality check to fail.
+            // So if it's a boolean, we'll explicitly coerce the value to a boolean.
+            const existingValue =
+                def.type === 'boolean' && typeof existingCustomFields?.[key] === 'number'
+                    ? !!existingCustomFields?.[key]
+                    : existingCustomFields?.[key];
             if (existingValue !== undefined) {
                 const valuesMatch =
                     JSON.stringify(inputCustomFields?.[key]) === JSON.stringify(existingValue);