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

Convert "Allow backorders?" into radio buttons #37282

Merged
merged 6 commits into from Mar 20, 2023

Conversation

octaedro
Copy link
Contributor

@octaedro octaedro commented Mar 16, 2023

All Submissions:

Changes proposed in this Pull Request:

This PR adds the code to convert the "Allow backorders?" dropdown into radio buttons.

If the number of items inside exceeds three, it should be displayed as a dropdown again.

screenshot-user-images githubusercontent com-2023 03 07-22_00_02 (3)

Closes #37118.

How to test the changes in this Pull Request:

  1. Go to Products > Add New > Product data > Inventory.
  2. Verify that the Allow backorders? uses a radio button to set that option.
  3. Install and activate this plugin to use a select instead of the radio buttons.

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?
  • Have you included testing instructions?

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.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 16, 2023
@codecov
Copy link

codecov bot commented Mar 16, 2023

Codecov Report

Merging #37282 (2786b10) into trunk (a2b02fc) will increase coverage by 0.0%.
The diff coverage is 84.1%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             trunk   #37282   +/-   ##
========================================
  Coverage     45.8%    45.8%           
  Complexity   17196    17196           
========================================
  Files          429      429           
  Lines        64909    64911    +2     
========================================
+ Hits         29701    29705    +4     
+ Misses       35208    35206    -2     
Impacted Files Coverage Δ
...lugins/woocommerce/includes/class-wc-post-data.php 64.4% <0.0%> (ø)
...udes/data-stores/class-wc-order-data-store-cpt.php 91.0% <ø> (ø)
...llers/Version3/class-wc-rest-orders-controller.php 79.8% <ø> (ø)
plugins/woocommerce/includes/wc-user-functions.php 78.0% <43.8%> (ø)
...gins/woocommerce/includes/wc-product-functions.php 44.9% <85.7%> (+0.2%) ⬆️
...s/data-stores/abstract-wc-order-data-store-cpt.php 92.5% <91.7%> (ø)
...ns/woocommerce/includes/class-wc-order-factory.php 79.2% <100.0%> (ø)
plugins/woocommerce/includes/class-wc-webhook.php 41.6% <100.0%> (ø)
...rs/Version2/class-wc-rest-orders-v2-controller.php 89.8% <100.0%> (ø)

... and 1 file with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2023

Test Results Summary

Commit SHA: 2786b10

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 48s
E2E Tests1910010020116m 20s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@octaedro octaedro marked this pull request as ready for review March 17, 2023 13:41
@octaedro octaedro self-assigned this Mar 17, 2023
@octaedro octaedro requested a review from a team March 17, 2023 13:41
@octaedro octaedro added focus: product management Related to product creation and editing. type: enhancement The issue is a request for an enhancement. labels Mar 17, 2023
@octaedro octaedro force-pushed the dev/37118_convert_allow_backorders_into_radio_buttons branch from 4e2c8e5 to 138e36a Compare March 20, 2023 13:58
Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

The default for the filter needs to be flipped. Ping me when ready for a re-review!

*
* @param bool If false, "Allow backorders?" will be shown as a select. Default: it will use radio buttons.
*/
if ( apply_filters( 'woocommerce_product_allow_backorder_use_radio', false ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The default should be true, otherwise, the radios are not used by default!

if ( apply_filters( 'woocommerce_product_allow_backorder_use_radio', false ) ) {
woocommerce_wp_radio( $common_backorder_args );
} else {
$select_input_args = array(
'desc_tip' => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as on #37278... I think we should keep the tip.

Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Tests well. Nice job! 🚀

Comment on lines +129 to +138
$stock_status_options = wc_get_product_stock_status_options();
$stock_status_count = count( $stock_status_options );
$stock_status_args = array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => $stock_status_options,
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes are not directly related to the PR. It would be good in the future to either split them out or, since this is admittedly a small change and closely related, just reference that the change was made in the PR description/comments, so it is clear to the reviewer!

@octaedro octaedro merged commit a51f26d into trunk Mar 20, 2023
20 checks passed
@octaedro octaedro deleted the dev/37118_convert_allow_backorders_into_radio_buttons branch March 20, 2023 18:41
@github-actions github-actions bot added this to the 7.6.0 milestone Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: product management Related to product creation and editing. plugin: woocommerce Issues related to the WooCommerce Core plugin. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Convert "Allow backorders?" into radio buttons
2 participants