Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 7e6bd4a

Browse files
github-actions[bot]github-actionstarhi-saadsenadirmikejolley
authored
Release: 9.6.1 (#8466)
* Empty commit for release pull request * Add changelog to readme.txt * Unset default customer state if it doesn't match country (#8460) * Unset default state * add controller for customers * rename validation file * explain fix inline * address feedback * revert back state logic * Update src/StoreApi/Utilities/ValidationUtils.php Co-authored-by: Mike Jolley <[email protected]> --------- Co-authored-by: Mike Jolley <[email protected]> * Update readme.txt * Add testing notes * Update testing notes * Fix Customer account sidebar link incorrect margin in WP 6.2 (#8437) * Fix Customer account sidebar link incorrect margin in WP 6.2 * Update class name to match the guidelines * Prevent cart from breaking when item_data contains an array (#8440) * Ensure array item data is removed * Remove unused key * Clean up code and add comments * Check for null instead of empty * Use plain foreach to filter and map arrays * Add minimum height to Mini Cart Contents block in the Style Book (#8458) * Update testing notes zip file * Update testing notes * Update testing notes file * Bumping version strings to new version. --------- Co-authored-by: github-actions <[email protected]> Co-authored-by: Saad Tarhi <[email protected]> Co-authored-by: Seghir Nadir <[email protected]> Co-authored-by: Mike Jolley <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Thomas Roberts <[email protected]>
1 parent 9748b11 commit 7e6bd4a

File tree

15 files changed

+180
-69
lines changed

15 files changed

+180
-69
lines changed

assets/js/blocks/customer-account/editor.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
width: 100%;
33
}
44

5-
.account-link {
5+
/* In sidebar without tabs (WP <=6.1) */
6+
.block-editor-block-card + div > .wc-block-editor-customer-account__link {
67
padding: 0 $gap $gap 52px;
78
}
9+
/* In tabbed sidebar (ie: WP >=6.2) */
10+
.wc-block-editor-customer-account__link {
11+
padding: $gap;
12+
}

assets/js/blocks/customer-account/sidebar-settings.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const AccountSettingsLink = () => {
4747
}
4848
);
4949

50-
return <div className="account-link">{ linkText }</div>;
50+
return (
51+
<div className="wc-block-editor-customer-account__link">
52+
{ linkText }
53+
</div>
54+
);
5155
};
5256

5357
export const BlockSettings = ( {

assets/js/blocks/mini-cart/mini-cart-contents/editor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@
7979
color: currentColor;
8080
}
8181
}
82+
83+
.editor-styles-wrapper .wp-block-woocommerce-mini-cart-contents,
84+
.editor-styles-wrapper .wp-block-woocommerce-filled-mini-cart-contents-block {
85+
height: auto;
86+
min-height: 500px;
87+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Testing notes and ZIP for release 9.6.1
2+
3+
Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/10767768/woocommerce-gutenberg-products-block.zip)
4+
5+
## WooCommerce Core
6+
7+
### Make Mini Cart Contents block visible in the Style Book. ([8458](https://github.com/woocommerce/woocommerce-blocks/pull/8458))
8+
9+
1. With Gutenberg installed and a block theme like [Twenty Twenty-Three](https://wordpress.org/themes/twentytwentythree/) enabled.
10+
2. Go to Appearance > Editor and edit a template.
11+
3. In the toolbar, select Styles (black and white circle) and then, Open Style Book (eye icon).
12+
4. Go to the WooCommerce tab.
13+
5. Ensure the Mini Cart Contents block is visible.
14+
15+
| Before | After |
16+
| ------ | ----- |
17+
| ![imatge](https://user-images.githubusercontent.com/3616980/219356399-cd2c16c1-4256-42e4-a59b-0a77d273ebc7.png) | ![imatge](https://user-images.githubusercontent.com/3616980/219356269-9cc6ece5-5f5f-4df9-8e57-dc158bcace8d.png) |
18+
19+
### Fix Customer account sidebar link incorrect margin in WP 6.2. ([8437](https://github.com/woocommerce/woocommerce-blocks/pull/8437))
20+
21+
1. In WP 6.1 without Gutenberg installed, verify there are no regressions:
22+
1. Add the Customer account block to a post or page.
23+
2. In the editor, open the sidebar and verify the Manage account settings link is displayed below the product description.
24+
2. In WP 6.2 or WP 6.1 with Gutenberg installed, verify the link has correct margins:
25+
1. Add the Customer account block to a post or page.
26+
2. In the editor, open the sidebar and verify the Manage account settings link has correct margins.
27+
28+
· | WP 6.1 without GB enabled | WP 6.1 with GB enabled |
29+
--- | --- | --- |
30+
Before | ![imatge](https://user-images.githubusercontent.com/3616980/219014857-6071a40e-8770-4f1f-b37c-91e5bf7451b5.png) | ![imatge](https://user-images.githubusercontent.com/3616980/219015103-982b2663-a15a-4101-9f24-83478b0e6eea.png) |
31+
After | ![imatge](https://user-images.githubusercontent.com/3616980/219014857-6071a40e-8770-4f1f-b37c-91e5bf7451b5.png) | ![imatge](https://user-images.githubusercontent.com/3616980/219014964-505597f7-2f52-42c8-91ad-04c130bfff78.png) |
32+
33+
### Fix cases in which Checkout would validate customer country against the wrong state. ([8460](https://github.com/woocommerce/woocommerce-blocks/pull/8460))
34+
35+
1. Set US/California as the default shipping destination.
36+
2. Add a product to the cart.
37+
3. Go to the checkout page.
38+
4. Select a different Shipping Country that has states, e.g. Greece.
39+
5. Fill in the city field.
40+
6. You should not get a error.
41+
7. Checkout without setting the state.
42+
8. In the admin, you should not see California as the state.

docs/internal-developers/testing/releases/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Every release includes specific testing instructions for new features and bug fi
119119
- [9.4.2](./942.md)
120120
- [9.5.0](./950.md)
121121
- [9.6.0](./960.md)
122+
- [9.6.1](./961.md)
122123

123124
<!-- FEEDBACK -->
124125

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@woocommerce/block-library",
33
"title": "WooCommerce Blocks",
44
"author": "Automattic",
5-
"version": "9.6.0",
5+
"version": "9.6.1",
66
"description": "WooCommerce blocks for the Gutenberg editor.",
77
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
88
"keywords": [

readme.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
44
Requires at least: 6.1.1
55
Tested up to: 6.1.1
66
Requires PHP: 7.2
7-
Stable tag: 9.6.0
7+
Stable tag: 9.6.1
88
License: GPLv3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010

@@ -80,6 +80,15 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/
8080

8181
== Changelog ==
8282

83+
= 9.6.1 - 2023-02-17 =
84+
85+
#### Bug Fixes
86+
87+
- Make Mini Cart Contents block visible in the Style Book. ([8458](https://github.com/woocommerce/woocommerce-blocks/pull/8458))
88+
- Fixed an issue where cart item data could cause fatal errors if it was an array. ([8440](https://github.com/woocommerce/woocommerce-blocks/pull/8440))
89+
- Fix Customer account sidebar link incorrect margin in WP 6.2. ([8437](https://github.com/woocommerce/woocommerce-blocks/pull/8437))
90+
- Fix cases in which Checkout would validate customer country against the wrong state. ([8460](https://github.com/woocommerce/woocommerce-blocks/pull/8460))
91+
8392
= 9.6.0 - 2023-02-14 =
8493

8594
#### Enhancements

src/Package.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static function container( $reset = false ) {
109109
NewPackage::class,
110110
function ( $container ) {
111111
// leave for automated version bumping.
112-
$version = '9.6.0';
112+
$version = '9.6.1';
113113
return new NewPackage(
114114
$version,
115115
dirname( __DIR__ ),

src/StoreApi/Routes/V1/CartUpdateCustomer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Automattic\WooCommerce\StoreApi\Routes\V1;
33

44
use Automattic\WooCommerce\StoreApi\Utilities\DraftOrderTrait;
5+
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
56

67
/**
78
* CartUpdateCustomer class.
@@ -215,16 +216,29 @@ protected function get_route_post_response( \WP_REST_Request $request ) {
215216
* @return array
216217
*/
217218
protected function get_customer_billing_address( \WC_Customer $customer ) {
219+
$validation_util = new ValidationUtils();
220+
$billing_country = $customer->get_billing_country();
221+
$billing_state = $customer->get_billing_state();
222+
223+
/**
224+
* There's a bug in WooCommerce core in which not having a state ("") would result in us validating against the store's state.
225+
* This resets the state to an empty string if it doesn't match the country.
226+
*
227+
* @todo Removing this handling once we fix the issue with the state value always being the store one.
228+
*/
229+
if ( ! $validation_util->validate_state( $billing_state, $billing_country ) ) {
230+
$billing_state = '';
231+
}
218232
return [
219233
'first_name' => $customer->get_billing_first_name(),
220234
'last_name' => $customer->get_billing_last_name(),
221235
'company' => $customer->get_billing_company(),
222236
'address_1' => $customer->get_billing_address_1(),
223237
'address_2' => $customer->get_billing_address_2(),
224238
'city' => $customer->get_billing_city(),
225-
'state' => $customer->get_billing_state(),
239+
'state' => $billing_state,
226240
'postcode' => $customer->get_billing_postcode(),
227-
'country' => $customer->get_billing_country(),
241+
'country' => $billing_country,
228242
'phone' => $customer->get_billing_phone(),
229243
'email' => $customer->get_billing_email(),
230244
];

src/StoreApi/Schemas/V1/AbstractAddressSchema.php

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
33

4+
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
5+
46
/**
57
* AddressSchema class.
68
*
@@ -87,6 +89,8 @@ public function get_properties() {
8789
* @return array
8890
*/
8991
public function sanitize_callback( $address, $request, $param ) {
92+
$validation_util = new ValidationUtils();
93+
9094
$address = array_merge( array_fill_keys( array_keys( $this->get_properties() ), '' ), (array) $address );
9195
$address['country'] = wc_strtoupper( wc_clean( wp_unslash( $address['country'] ) ) );
9296
$address['first_name'] = wc_clean( wp_unslash( $address['first_name'] ) );
@@ -95,64 +99,12 @@ public function sanitize_callback( $address, $request, $param ) {
9599
$address['address_1'] = wc_clean( wp_unslash( $address['address_1'] ) );
96100
$address['address_2'] = wc_clean( wp_unslash( $address['address_2'] ) );
97101
$address['city'] = wc_clean( wp_unslash( $address['city'] ) );
98-
$address['state'] = $this->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
102+
$address['state'] = $validation_util->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
99103
$address['postcode'] = $address['postcode'] ? wc_format_postcode( wc_clean( wp_unslash( $address['postcode'] ) ), $address['country'] ) : '';
100104
$address['phone'] = wc_clean( wp_unslash( $address['phone'] ) );
101105
return $address;
102106
}
103107

104-
/**
105-
* Get list of states for a country.
106-
*
107-
* @param string $country Country code.
108-
* @return array Array of state names indexed by state keys.
109-
*/
110-
protected function get_states_for_country( $country ) {
111-
return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
112-
}
113-
114-
/**
115-
* Validate provided state against a countries list of defined states.
116-
*
117-
* If there are no defined states for a country, any given state is valid.
118-
*
119-
* @param string $state State name or code (sanitized).
120-
* @param string $country Country code.
121-
* @return boolean Valid or not valid.
122-
*/
123-
protected function validate_state( $state, $country ) {
124-
$states = $this->get_states_for_country( $country );
125-
126-
if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
127-
return false;
128-
}
129-
130-
return true;
131-
}
132-
133-
/**
134-
* Format a state based on the country. If country has defined states, will return a valid upper case state code.
135-
*
136-
* @param string $state State name or code (sanitized).
137-
* @param string $country Country code.
138-
* @return string
139-
*/
140-
protected function format_state( $state, $country ) {
141-
$states = $this->get_states_for_country( $country );
142-
143-
if ( count( $states ) ) {
144-
$state = \wc_strtoupper( $state );
145-
$state_values = array_map( 'wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
146-
147-
if ( isset( $state_values[ $state ] ) ) {
148-
// Convert to state code if a state name was provided.
149-
return $state_values[ $state ];
150-
}
151-
}
152-
153-
return $state;
154-
}
155-
156108
/**
157109
* Validate the given address object.
158110
*
@@ -164,8 +116,9 @@ protected function format_state( $state, $country ) {
164116
* @return true|\WP_Error
165117
*/
166118
public function validate_callback( $address, $request, $param ) {
167-
$errors = new \WP_Error();
168-
$address = $this->sanitize_callback( $address, $request, $param );
119+
$errors = new \WP_Error();
120+
$address = $this->sanitize_callback( $address, $request, $param );
121+
$validation_util = new ValidationUtils();
169122

170123
if ( ! empty( $address['country'] ) && ! in_array( $address['country'], array_keys( wc()->countries->get_countries() ), true ) ) {
171124
$errors->add(
@@ -179,14 +132,14 @@ public function validate_callback( $address, $request, $param ) {
179132
return $errors;
180133
}
181134

182-
if ( ! empty( $address['state'] ) && ! $this->validate_state( $address['state'], $address['country'] ) ) {
135+
if ( ! empty( $address['state'] ) && ! $validation_util->validate_state( $address['state'], $address['country'] ) ) {
183136
$errors->add(
184137
'invalid_state',
185138
sprintf(
186139
/* translators: %1$s given state, %2$s valid states */
187140
__( 'The provided state (%1$s) is not valid. Must be one of: %2$s', 'woo-gutenberg-products-block' ),
188141
esc_html( $address['state'] ),
189-
implode( ', ', array_keys( $this->get_states_for_country( $address['country'] ) ) )
142+
implode( ', ', array_keys( $validation_util->get_states_for_country( $address['country'] ) ) )
190143
)
191144
);
192145
}

0 commit comments

Comments
 (0)