Error on product _validateSerializedArray with a single variant product
See original GitHub issueError on a fresh yarn create slate-theme
product page, adding a single variant product to the cart.
Perhaps related to #85 ?
Console output:
Error: is empty.
at _validateSerializedArray (webpack-internal:///../node_modules/@shopify/theme-product/theme-product.js:109:11)
at _createOptionArrayFromOptionCollection (webpack-internal:///../node_modules/@shopify/theme-product/theme-product.js:67:3)
at getVariantFromSerializedArray (webpack-internal:///../node_modules/@shopify/theme-product/theme-product.js:35:21)
at ProductForm.variant (webpack-internal:///../node_modules/@shopify/theme-product-form/theme-product-form.js:105:102)
at ProductForm._getProductFormEventData (webpack-internal:///../node_modules/@shopify/theme-product-form/theme-product-form.js:186:19)
at ProductForm._onSubmit (webpack-internal:///../node_modules/@shopify/theme-product-form/theme-product-form.js:150:24)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
rails serialized array validation - Stack Overflow
validates_each is for validating multiple attributes. In your case you have one attribute, and you need to validate it in a custom way....
Read more >CWE-20: Improper Input Validation (4.9) - MITRE
The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required...
Read more >[MS-FSRM]: ExportTemplates (Opnum 10) | Microsoft Learn
fileScreenTemplateNamesArray : Pointer to a SAFEARRAY that contains the ... Upon successful validation of parameters, the server MUST perform one of the ...
Read more >craft\commerce\elements\Variant
Whether the variant was deleted along with its product ... (opens new window), Returns the errors for all attributes as a one-dimensional array....
Read more >Node.js v19.3.0 Documentation
Be aware that in the repl the error message will be different to the one thrown ... is not an Array or another...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The JS code expects a non-empty array with options. The array is collected from the form elements with names like “name=options[OptionName]”.
The recommended liquid snippet contains logic like:
{% unless product.has_only_default_variant %}
some elements with the required names created{% endunless %}
Thus, no options elements for the single variant products.
Meanwhile, until it has been fixed in JS, I use slightly different logic:
{% if product.has_only_default_variant != true %}
as it were{% else %}
<input type="hidden" id="defaultOption" name="options[Title]" value="Default title">
{% endif %}
So, a fake option created. Of course, it may confuse the further processors:
ProductForm.options()
will return non-empty list for the single variant product. At least, it does not throw error.I also ran into this issue. I believe a more thorough, readable solution is: