* Empty commit for release pull request

* Add changelog to readme.txt

* Unset default customer state if it doesn't match country (https://github.com/woocommerce/woocommerce-blocks/pull/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 <mike.jolley@me.com>

---------

Co-authored-by: Mike Jolley <mike.jolley@me.com>

* Update readme.txt

* Add testing notes

* Update testing notes

* Fix Customer account sidebar link incorrect margin in WP 6.2 (https://github.com/woocommerce/woocommerce-blocks/pull/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 (https://github.com/woocommerce/woocommerce-blocks/pull/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 (https://github.com/woocommerce/woocommerce-blocks/pull/8458)

* Update testing notes zip file

* Update testing notes

* Update testing notes file

* Bumping version strings to new version.

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2023-02-17 16:29:48 +01:00 committed by GitHub
parent 23509b6839
commit e5ba22df0d
15 changed files with 180 additions and 69 deletions

View File

@ -2,6 +2,11 @@
width: 100%;
}
.account-link {
/* In sidebar without tabs (WP <=6.1) */
.block-editor-block-card + div > .wc-block-editor-customer-account__link {
padding: 0 $gap $gap 52px;
}
/* In tabbed sidebar (ie: WP >=6.2) */
.wc-block-editor-customer-account__link {
padding: $gap;
}

View File

@ -47,7 +47,11 @@ const AccountSettingsLink = () => {
}
);
return <div className="account-link">{ linkText }</div>;
return (
<div className="wc-block-editor-customer-account__link">
{ linkText }
</div>
);
};
export const BlockSettings = ( {

View File

@ -79,3 +79,9 @@
color: currentColor;
}
}
.editor-styles-wrapper .wp-block-woocommerce-mini-cart-contents,
.editor-styles-wrapper .wp-block-woocommerce-filled-mini-cart-contents-block {
height: auto;
min-height: 500px;
}

View File

@ -0,0 +1,42 @@
# Testing notes and ZIP for release 9.6.1
Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/10767768/woocommerce-gutenberg-products-block.zip)
## WooCommerce Core
### Make Mini Cart Contents block visible in the Style Book. ([8458](https://github.com/woocommerce/woocommerce-blocks/pull/8458))
1. With Gutenberg installed and a block theme like [Twenty Twenty-Three](https://wordpress.org/themes/twentytwentythree/) enabled.
2. Go to Appearance > Editor and edit a template.
3. In the toolbar, select Styles (black and white circle) and then, Open Style Book (eye icon).
4. Go to the WooCommerce tab.
5. Ensure the Mini Cart Contents block is visible.
| Before | After |
| ------ | ----- |
| ![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) |
### Fix Customer account sidebar link incorrect margin in WP 6.2. ([8437](https://github.com/woocommerce/woocommerce-blocks/pull/8437))
1. In WP 6.1 without Gutenberg installed, verify there are no regressions:
1. Add the Customer account block to a post or page.
2. In the editor, open the sidebar and verify the Manage account settings link is displayed below the product description.
2. In WP 6.2 or WP 6.1 with Gutenberg installed, verify the link has correct margins:
1. Add the Customer account block to a post or page.
2. In the editor, open the sidebar and verify the Manage account settings link has correct margins.
· | WP 6.1 without GB enabled | WP 6.1 with GB enabled |
--- | --- | --- |
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) |
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) |
### Fix cases in which Checkout would validate customer country against the wrong state. ([8460](https://github.com/woocommerce/woocommerce-blocks/pull/8460))
1. Set US/California as the default shipping destination.
2. Add a product to the cart.
3. Go to the checkout page.
4. Select a different Shipping Country that has states, e.g. Greece.
5. Fill in the city field.
6. You should not get a error.
7. Checkout without setting the state.
8. In the admin, you should not see California as the state.

View File

@ -119,6 +119,7 @@ Every release includes specific testing instructions for new features and bug fi
- [9.4.2](./942.md)
- [9.5.0](./950.md)
- [9.6.0](./960.md)
- [9.6.1](./961.md)
<!-- FEEDBACK -->

View File

@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
"version": "9.6.0",
"version": "9.6.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [

View File

@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 6.1.1
Tested up to: 6.1.1
Requires PHP: 7.2
Stable tag: 9.6.0
Stable tag: 9.6.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@ -80,6 +80,15 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/
== Changelog ==
= 9.6.1 - 2023-02-17 =
#### Bug Fixes
- Make Mini Cart Contents block visible in the Style Book. ([8458](https://github.com/woocommerce/woocommerce-blocks/pull/8458))
- 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))
- Fix Customer account sidebar link incorrect margin in WP 6.2. ([8437](https://github.com/woocommerce/woocommerce-blocks/pull/8437))
- Fix cases in which Checkout would validate customer country against the wrong state. ([8460](https://github.com/woocommerce/woocommerce-blocks/pull/8460))
= 9.6.0 - 2023-02-14 =
#### Enhancements

View File

@ -109,7 +109,7 @@ class Package {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '9.6.0';
$version = '9.6.1';
return new NewPackage(
$version,
dirname( __DIR__ ),

View File

@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\StoreApi\Routes\V1;
use Automattic\WooCommerce\StoreApi\Utilities\DraftOrderTrait;
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
/**
* CartUpdateCustomer class.
@ -215,6 +216,19 @@ class CartUpdateCustomer extends AbstractCartRoute {
* @return array
*/
protected function get_customer_billing_address( \WC_Customer $customer ) {
$validation_util = new ValidationUtils();
$billing_country = $customer->get_billing_country();
$billing_state = $customer->get_billing_state();
/**
* There's a bug in WooCommerce core in which not having a state ("") would result in us validating against the store's state.
* This resets the state to an empty string if it doesn't match the country.
*
* @todo Removing this handling once we fix the issue with the state value always being the store one.
*/
if ( ! $validation_util->validate_state( $billing_state, $billing_country ) ) {
$billing_state = '';
}
return [
'first_name' => $customer->get_billing_first_name(),
'last_name' => $customer->get_billing_last_name(),
@ -222,9 +236,9 @@ class CartUpdateCustomer extends AbstractCartRoute {
'address_1' => $customer->get_billing_address_1(),
'address_2' => $customer->get_billing_address_2(),
'city' => $customer->get_billing_city(),
'state' => $customer->get_billing_state(),
'state' => $billing_state,
'postcode' => $customer->get_billing_postcode(),
'country' => $customer->get_billing_country(),
'country' => $billing_country,
'phone' => $customer->get_billing_phone(),
'email' => $customer->get_billing_email(),
];

View File

@ -1,6 +1,8 @@
<?php
namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
/**
* AddressSchema class.
*
@ -87,6 +89,8 @@ abstract class AbstractAddressSchema extends AbstractSchema {
* @return array
*/
public function sanitize_callback( $address, $request, $param ) {
$validation_util = new ValidationUtils();
$address = array_merge( array_fill_keys( array_keys( $this->get_properties() ), '' ), (array) $address );
$address['country'] = wc_strtoupper( wc_clean( wp_unslash( $address['country'] ) ) );
$address['first_name'] = wc_clean( wp_unslash( $address['first_name'] ) );
@ -95,64 +99,12 @@ abstract class AbstractAddressSchema extends AbstractSchema {
$address['address_1'] = wc_clean( wp_unslash( $address['address_1'] ) );
$address['address_2'] = wc_clean( wp_unslash( $address['address_2'] ) );
$address['city'] = wc_clean( wp_unslash( $address['city'] ) );
$address['state'] = $this->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
$address['state'] = $validation_util->format_state( wc_clean( wp_unslash( $address['state'] ) ), $address['country'] );
$address['postcode'] = $address['postcode'] ? wc_format_postcode( wc_clean( wp_unslash( $address['postcode'] ) ), $address['country'] ) : '';
$address['phone'] = wc_clean( wp_unslash( $address['phone'] ) );
return $address;
}
/**
* Get list of states for a country.
*
* @param string $country Country code.
* @return array Array of state names indexed by state keys.
*/
protected function get_states_for_country( $country ) {
return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
}
/**
* Validate provided state against a countries list of defined states.
*
* If there are no defined states for a country, any given state is valid.
*
* @param string $state State name or code (sanitized).
* @param string $country Country code.
* @return boolean Valid or not valid.
*/
protected function validate_state( $state, $country ) {
$states = $this->get_states_for_country( $country );
if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
return false;
}
return true;
}
/**
* Format a state based on the country. If country has defined states, will return a valid upper case state code.
*
* @param string $state State name or code (sanitized).
* @param string $country Country code.
* @return string
*/
protected function format_state( $state, $country ) {
$states = $this->get_states_for_country( $country );
if ( count( $states ) ) {
$state = \wc_strtoupper( $state );
$state_values = array_map( 'wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
if ( isset( $state_values[ $state ] ) ) {
// Convert to state code if a state name was provided.
return $state_values[ $state ];
}
}
return $state;
}
/**
* Validate the given address object.
*
@ -164,8 +116,9 @@ abstract class AbstractAddressSchema extends AbstractSchema {
* @return true|\WP_Error
*/
public function validate_callback( $address, $request, $param ) {
$errors = new \WP_Error();
$address = $this->sanitize_callback( $address, $request, $param );
$errors = new \WP_Error();
$address = $this->sanitize_callback( $address, $request, $param );
$validation_util = new ValidationUtils();
if ( ! empty( $address['country'] ) && ! in_array( $address['country'], array_keys( wc()->countries->get_countries() ), true ) ) {
$errors->add(
@ -179,14 +132,14 @@ abstract class AbstractAddressSchema extends AbstractSchema {
return $errors;
}
if ( ! empty( $address['state'] ) && ! $this->validate_state( $address['state'], $address['country'] ) ) {
if ( ! empty( $address['state'] ) && ! $validation_util->validate_state( $address['state'], $address['country'] ) ) {
$errors->add(
'invalid_state',
sprintf(
/* translators: %1$s given state, %2$s valid states */
__( 'The provided state (%1$s) is not valid. Must be one of: %2$s', 'woo-gutenberg-products-block' ),
esc_html( $address['state'] ),
implode( ', ', array_keys( $this->get_states_for_country( $address['country'] ) ) )
implode( ', ', array_keys( $validation_util->get_states_for_country( $address['country'] ) ) )
)
);
}

View File

@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
/**
* BillingAddressSchema class.
@ -89,11 +90,12 @@ class BillingAddressSchema extends AbstractAddressSchema {
* @return stdClass
*/
public function get_item_response( $address ) {
$validation_util = new ValidationUtils();
if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
$billing_country = $address->get_billing_country();
$billing_state = $address->get_billing_state();
if ( ! $this->validate_state( $billing_state, $billing_country ) ) {
if ( ! $validation_util->validate_state( $billing_state, $billing_country ) ) {
$billing_state = '';
}

View File

@ -458,8 +458,20 @@ class CartItemSchema extends ProductSchema {
* @param array $cart_item Cart item array.
* @return array
*/
$item_data = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
return array_map( [ $this, 'format_item_data_element' ], $item_data );
$item_data = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
$clean_item_data = [];
foreach ( $item_data as $data ) {
// We will check each piece of data in the item data element to ensure it is scalar. Extensions could add arrays
// to this, which would cause a fatal in wp_strip_all_tags. If it is not scalar, we will return an empty array,
// which will be filtered out in get_item_data (after this function has run).
foreach ( $data as $data_value ) {
if ( ! is_scalar( $data_value ) ) {
continue 2;
}
}
$clean_item_data[] = $this->format_item_data_element( $data );
}
return $clean_item_data;
}
/**

View File

@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\StoreApi\Schemas\V1;
use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
use Automattic\WooCommerce\StoreApi\Utilities\ValidationUtils;
/**
* ShippingAddressSchema class.
@ -32,11 +33,12 @@ class ShippingAddressSchema extends AbstractAddressSchema {
* @return stdClass
*/
public function get_item_response( $address ) {
$validation_util = new ValidationUtils();
if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
$shipping_country = $address->get_shipping_country();
$shipping_state = $address->get_shipping_state();
if ( ! $this->validate_state( $shipping_state, $shipping_country ) ) {
if ( ! $validation_util->validate_state( $shipping_state, $shipping_country ) ) {
$shipping_state = '';
}

View File

@ -0,0 +1,61 @@
<?php
namespace Automattic\WooCommerce\StoreApi\Utilities;
/**
* ValidationUtils class.
* Helper class which validates and update customer info.
*/
class ValidationUtils {
/**
* Get list of states for a country.
*
* @param string $country Country code.
* @return array Array of state names indexed by state keys.
*/
public function get_states_for_country( $country ) {
return $country ? array_filter( (array) \wc()->countries->get_states( $country ) ) : [];
}
/**
* Validate provided state against a countries list of defined states.
*
* If there are no defined states for a country, any given state is valid.
*
* @param string $state State name or code (sanitized).
* @param string $country Country code.
* @return boolean Valid or not valid.
*/
public function validate_state( $state, $country ) {
$states = $this->get_states_for_country( $country );
if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
return false;
}
return true;
}
/**
* Format a state based on the country. If country has defined states, will return a valid upper case state code.
*
* @param string $state State name or code (sanitized).
* @param string $country Country code.
* @return string
*/
public function format_state( $state, $country ) {
$states = $this->get_states_for_country( $country );
if ( count( $states ) ) {
$state = \wc_strtoupper( $state );
$state_values = array_map( '\wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );
if ( isset( $state_values[ $state ] ) ) {
// Convert to state code if a state name was provided.
return $state_values[ $state ];
}
}
return $state;
}
}

View File

@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Blocks
* Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block
* Description: WooCommerce blocks for the Gutenberg editor.
* Version: 9.6.0
* Version: 9.6.1
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block