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

[Experiment] Fix additional address field validation notices #44615

Merged
merged 4 commits into from Feb 14, 2024

Conversation

mikejolley
Copy link
Member

Submission Review Guidelines:

Changes proposed in this Pull Request:

Fixes 2 issues with additional fields blocking checkout with notices:

  1. When using a checkbox address field, update events would show a notice because the value was posted as a string
  2. When using select boxes, on first checkout the user would be forced to make a selection even if not applicable. Fields can now be optional.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

Test snippet:

add_action(
	'woocommerce_blocks_loaded',
	function() {
		woocommerce_blocks_register_checkout_field(
			array(
				'id'       => 'plugin-namespace/address-field',
				'label'    => __( 'Test checkbox', 'woocommerce' ),
				'location' => 'address',
				'type'     => 'checkbox',
			),
		);
		woocommerce_blocks_register_checkout_field(
			array(
				'id'       => 'plugin-namespace/leave-on-porch2',
				'label'    => __( 'Please leave my package on the porch if I\'m not home', 'woocommerce' ),
				'location' => 'additional',
				'type'     => 'checkbox',
			),
		);
		woocommerce_blocks_register_checkout_field(
			array(
				'id'       => 'plugin-namespace/location-on-porch2',
				'label'    => __( 'Describe where we should hide the parcel', 'woocommerce' ),
				'location' => 'additional',
				'type'     => 'text',
			)
		);
		woocommerce_blocks_register_checkout_field(
			array(
				'id'       => 'plugin-namespace/leave-with-neighbor2',
				'label'    => __( 'Which neighbor should we leave it with if unable to hide?', 'woocommerce' ),
				'location' => 'additional',
				'type'     => 'select',
				'required' => false,
				'options'  => array(
					array(
						'label' => 'Neighbor to the left',
						'value' => 'left',
					),
					array(
						'label' => 'Neighbor to the right',
						'value' => 'right',
					),
					array(
						'label' => 'Neighbor across the road',
						'value' => 'across',
					),
					array(
						'label' => 'Do not leave with a neighbor',
						'value' => 'none',
					),
				),
			)
		);
	}
);
  1. Checkout and edit address. Do not check the custom checkbox and do not select an option for "Which neighbor should we leave it with if unable to hide?". Checkout should proceed without error.
  2. Checkout again and edit the zip code. After update, there should be no validation errors surfaced.
  3. Choose a value for "Which neighbor should we leave it with if unable to hide?" and ensure it persists after checkout.

This requires doc updates @opr

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 14, 2024
@mikejolley mikejolley self-assigned this Feb 14, 2024
@mikejolley mikejolley marked this pull request as ready for review February 14, 2024 14:31
@woocommercebot woocommercebot requested review from a team and tarunvijwani and removed request for a team February 14, 2024 14:31
Copy link
Contributor

github-actions bot commented Feb 14, 2024

Hi @opr, @tarunvijwani,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@mikejolley mikejolley requested a review from opr February 14, 2024 14:32
Copy link
Contributor

github-actions bot commented Feb 14, 2024

Test Results Summary

Commit SHA: 454ae46

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests298002303217m 22s

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.

Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

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

Just need a change to the condition for the empty value currently it's not working

Significance: patch
Type: update

This is behind a feature flag.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be Comment: This is behind a feature flag. to prevent being added to the actual changelog

@@ -469,6 +462,20 @@ private function process_select_field( $field_data, $options ) {
}

$field_data['options'] = $cleaned_options;

// If the field is not required, inject an empty option at the start.
if ( isset( $options['required'] ) && false === $options['required'] && ! in_array( '', $added_values, true ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to get $field_data['required'] instead here, $options doesn't contain required

@mikejolley mikejolley requested a review from opr February 14, 2024 16:43
@mikejolley mikejolley force-pushed the fix/additional-address-field-validation-notices branch from 8bf1617 to 454ae46 Compare February 14, 2024 16:59
Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

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

Working for me!

@opr opr merged commit b94c14e into trunk Feb 14, 2024
46 checks passed
@opr opr deleted the fix/additional-address-field-validation-notices branch February 14, 2024 18:02
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 14, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 14, 2024
@alopezari alopezari added status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 15, 2024
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. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants