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 selectors for quantity element in variable products #36871

Conversation

clustercis
Copy link
Contributor

@clustercis clustercis commented Feb 17, 2023

All Submissions:

Changes proposed in this Pull Request:

Closes #36855 to fix bug introduced by PR #36087.
Also addresses original issue #36086.

Edit 2023-02-20 (added details from commit message):
WooCommerce 7.4.0 changed the jQuery selectors for the quantity input in variable products.

This PR reinstates the previous logic so that $qty points to the div wrapper, and $qty_input points to the input element inside.

Otherwise, as is in the affected version, $qty_input is undefined and the min/max attributes are not updated.

It also addresses the original issue #36086 by restricting the selector of the div wrapper to only be the one containing input[name=quantity] (the .qty class filter is also kept to avoid any potential malfunctions of existing code).

How to test the changes in this Pull Request:

Quantity selector works properly (adapted from steps to reproduce in #36855):

  1. Create a variable product with some variations.
  2. Set a variation to "manage stock".
  3. Set the variation's "Stock quantity".
  4. Set the variation to "Do not allow" backorders.
  5. View the product from the front end.
  6. Pick the variation.
  7. Try increasing the quantity higher than what you set the stock quantity to.
  8. The input should now enforce the max limit so the value should not change above the set quantity.

Quantity selector does not affect other inputs (adapted from testing instructions in #36087):

Add the following snippet, which adds a new quantity input to the single variation:

function kia_test_single_variation_qty() {
	echo '<div class="quantity"><input class="qty" type="number" name="tacos" /></div>';
}
add_action( 'woocommerce_before_single_variation', 'kia_test_single_variation_qty' );
  1. Go to the variable product above.
  2. Select a variation by selecting the attributes necessary.
  3. Increase the rogue quantity input's value.
  4. Change to another variation.
  5. The main quantity input's value should stay the same.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

cc @barryhughes

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Feb 17, 2023
@woocommercebot woocommercebot requested review from a team and jorgeatorres and removed request for a team February 17, 2023 12:48
@clustercis clustercis changed the title Issues/36855 fix selector for variable qty Fix selectors for quantity element in variable products Feb 17, 2023
…antity selector of variable products

Fixes bug introduced in PR woocommerce#36087 that changes jQuery selectors for quantity input in variable products.

The previous logic is reinstated so that $qty points to the div wrapper,
and $qty_input points to the input element inside.

Otherwise, as is in the current version, $qty_input is undefined and the
min/max attributes are not updated.

This PR also addresses the original issue woocommerce#36086 by restricting the
selector of the div wrapper to only be the one containing
input[name=quantity] (the .qty class filter is also kept to avoid any
potential malfunctions of existing code).
@clustercis clustercis force-pushed the issues/36855-fix-selector-for-variable-qty branch from ec2a60c to e0aa482 Compare February 17, 2023 12:56
@codecov
Copy link

codecov bot commented Feb 19, 2023

Codecov Report

Merging #36871 (db2986d) into trunk (2e146d5) will increase coverage by 0.0%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             trunk   #36871   +/-   ##
========================================
  Coverage     46.7%    46.7%           
  Complexity   17171    17171           
========================================
  Files          429      429           
  Lines        64762    64762           
========================================
+ Hits         30220    30222    +2     
+ Misses       34542    34540    -2     
Impacted Files Coverage Δ
plugins/woocommerce/includes/class-wc-tax.php 79.0% <0.0%> (+0.5%) ⬆️

@Konamiman Konamiman self-requested a review February 22, 2023 09:51
@Konamiman Konamiman added this to the 7.5.0 milestone Feb 22, 2023
@Konamiman Konamiman merged commit 7feaed7 into woocommerce:trunk Feb 22, 2023
@jonathansadowski jonathansadowski modified the milestone: 7.5.0 Mar 17, 2023
github-actions bot pushed a commit that referenced this pull request Mar 17, 2023
Fixes bug introduced in PR #36087 that changes jQuery selectors for quantity input in variable products.

The previous logic is reinstated so that $qty points to the div wrapper, and $qty_input points to the input element inside.

Otherwise, as is in the current version, $qty_input is undefined and the min/max attributes are not updated.

This PR also addresses the original issue #36086 by restricting the selector of the div wrapper to only be the one containing input[name=quantity] (the .qty class filter is also kept to avoid any potential malfunctions of existing code).
jonathansadowski pushed a commit that referenced this pull request Mar 17, 2023
* Fix selectors for quantity element in variable products (#36871)

Fixes bug introduced in PR #36087 that changes jQuery selectors for quantity input in variable products.

The previous logic is reinstated so that $qty points to the div wrapper, and $qty_input points to the input element inside.

Otherwise, as is in the current version, $qty_input is undefined and the min/max attributes are not updated.

This PR also addresses the original issue #36086 by restricting the selector of the div wrapper to only be the one containing input[name=quantity] (the .qty class filter is also kept to avoid any potential malfunctions of existing code).

* Prep for cherry pick 36871

---------

Co-authored-by: Cluster CIS <37690192+clustercis@users.noreply.github.com>
Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Variation Max value is empty
3 participants