Performance: Move collectableMethodIds to cart/checkout block assets rather than loading it sitewide (#51174)
* Move collectableMethodIds to cart/checkout block assets * changelog
This commit is contained in:
parent
d4cc6578c7
commit
d87c3d38d7
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: performance
|
||||||
|
|
||||||
|
Only load local pickup methods on cart/checkout pages
|
|
@ -245,8 +245,12 @@ class Cart extends AbstractBlock {
|
||||||
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
|
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
|
||||||
$this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
|
$this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
|
||||||
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
|
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
|
||||||
|
|
||||||
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
|
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
|
||||||
|
$local_pickup_method_ids = LocalPickupUtils::get_local_pickup_method_ids();
|
||||||
|
|
||||||
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
|
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
|
||||||
|
$this->asset_data_registry->add( 'collectableMethodIds', $local_pickup_method_ids );
|
||||||
|
|
||||||
// Hydrate the following data depending on admin or frontend context.
|
// Hydrate the following data depending on admin or frontend context.
|
||||||
if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
|
if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
|
||||||
|
|
|
@ -370,8 +370,11 @@ class Checkout extends AbstractBlock {
|
||||||
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
|
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
|
||||||
|
|
||||||
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
|
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
|
||||||
|
$local_pickup_method_ids = LocalPickupUtils::get_local_pickup_method_ids();
|
||||||
|
|
||||||
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
|
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
|
||||||
$this->asset_data_registry->add( 'localPickupText', $pickup_location_settings['title'] );
|
$this->asset_data_registry->add( 'localPickupText', $pickup_location_settings['title'] );
|
||||||
|
$this->asset_data_registry->add( 'collectableMethodIds', $local_pickup_method_ids );
|
||||||
|
|
||||||
$is_block_editor = $this->is_block_editor();
|
$is_block_editor = $this->is_block_editor();
|
||||||
|
|
||||||
|
@ -385,8 +388,8 @@ class Checkout extends AbstractBlock {
|
||||||
$shipping_methods = WC()->shipping()->get_shipping_methods();
|
$shipping_methods = WC()->shipping()->get_shipping_methods();
|
||||||
$formatted_shipping_methods = array_reduce(
|
$formatted_shipping_methods = array_reduce(
|
||||||
$shipping_methods,
|
$shipping_methods,
|
||||||
function ( $acc, $method ) {
|
function ( $acc, $method ) use ( $local_pickup_method_ids ) {
|
||||||
if ( in_array( $method->id, LocalPickupUtils::get_local_pickup_method_ids(), true ) ) {
|
if ( in_array( $method->id, $local_pickup_method_ids, true ) ) {
|
||||||
return $acc;
|
return $acc;
|
||||||
}
|
}
|
||||||
if ( $method->supports( 'settings' ) ) {
|
if ( $method->supports( 'settings' ) ) {
|
||||||
|
|
|
@ -60,8 +60,6 @@ class ShippingController {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->asset_data_registry->add( 'collectableMethodIds', array( 'Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils', 'get_local_pickup_method_ids' ) );
|
|
||||||
$this->asset_data_registry->add( 'shippingCostRequiresAddress', get_option( 'woocommerce_shipping_cost_requires_address', false ) === 'yes' );
|
$this->asset_data_registry->add( 'shippingCostRequiresAddress', get_option( 'woocommerce_shipping_cost_requires_address', false ) === 'yes' );
|
||||||
add_action( 'rest_api_init', array( $this, 'register_settings' ) );
|
add_action( 'rest_api_init', array( $this, 'register_settings' ) );
|
||||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
|
||||||
|
|
Loading…
Reference in New Issue