question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on product _validateSerializedArray with a single variant product

See original GitHub issue

Error 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:open
  • Created 4 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

3reactions
tms320ccommented, Aug 1, 2019

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.

2reactions
cfxdcommented, Jul 19, 2021

I also ran into this issue. I believe a more thorough, readable solution is:

{% if product.has_only_default_variant %}
  {% assign option = product.options_with_values[0] %}
  {% assign value = option.values[0] %}
  <input type="hidden" id="Option{{ option.position }}-{{ value }}" name="options[{{ option.name }}]" value="{{ value }}">
{% else %}
  (current unless block)
{% endif %}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found