Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-js variant select on Featured Product #736

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

LucasLacerdaUX
Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX commented Oct 5, 2021

Why are these changes introduced?
When JavaScript is disabled, only initial variant could be added to cart, regardless of which variant was selected. This PR fixes this issue by replicating the same solution implemented by #210 on main-product.liquid

Fixes #179.

What approach did you take?

  • Disabled the "master" input, only used by JS variants.
  • Updated the no-js <select> element to use the correct Form ID.

Demo links

**Testing 🎩 **

  • Add a Featured Product section with a product that has multiple variants.
  • Use Developer Tools to disable JavaScript
  • Navigate to the Featured Product section and select a different variant. Click the Add to Cart button.
  • The correct variant should be added to the cart page.

Checklist

tyleralsbury
tyleralsbury previously approved these changes Oct 6, 2021
Copy link
Contributor

@tyleralsbury tyleralsbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with and without JS enabled.

sofiamatulis
sofiamatulis previously approved these changes Oct 6, 2021
Copy link
Contributor

@sofiamatulis sofiamatulis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it and it looks good 😄

@@ -2,97 +2,248 @@
"sections": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to revert these files

@@ -1,5 +1,33 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one

@@ -286,7 +286,7 @@
</div>

{%- form 'product', product, id: product_form_id, class: 'form', novalidate: 'novalidate', data-type: 'add-to-cart-form' -%}
<input type="hidden" disabled name="id" value="{{ product.selected_or_first_available_variant.id }}">
<input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}" disabled>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm I understand, you added disabled to ensure that this input isnt used when we are on the no-js version. Correct? Because this input is actually only used for the js version and the input value was being updated when we didnt want it to

Copy link
Contributor Author

@LucasLacerdaUX LucasLacerdaUX Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is reproducing the same fix from #210.

We're disabling this input so only the <select>, which has the same name, is seen by the no-js version.

This input is re-enabled via JS on product-form.js constructor:

@LucasLacerdaUX LucasLacerdaUX merged commit 9658a9c into main Oct 6, 2021
@LucasLacerdaUX LucasLacerdaUX deleted the featured-product-variant-fix branch October 6, 2021 18:07
@florin-a
Copy link

This kindof breaks add to cart on browsers that dont support custom elements.
Another way to go (and what I did) was to replace the selector on no-js with button links to the product defaulting to that variant. This way you get to also change the image.

phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add to cart does not work with JS disabled
4 participants