Load countries in settings only when a block requires them (https://github.com/woocommerce/woocommerce-blocks/pull/1726)

This commit is contained in:
Albert Juhé Lluveras 2020-02-13 13:52:04 +01:00 committed by GitHub
parent 2320b8aa75
commit bd8bd4f009
3 changed files with 13 additions and 2 deletions

View File

@ -129,8 +129,6 @@ class Assets {
'productCount' => array_sum( (array) $product_counts ), 'productCount' => array_sum( (array) $product_counts ),
'attributes' => array_values( wc_get_attribute_taxonomies() ), 'attributes' => array_values( wc_get_attribute_taxonomies() ),
'wcBlocksAssetUrl' => plugins_url( 'assets/', __DIR__ ), 'wcBlocksAssetUrl' => plugins_url( 'assets/', __DIR__ ),
'shippingCountries' => WC()->countries->get_shipping_countries(),
'allowedCountries' => WC()->countries->get_allowed_countries(),
'restApiRoutes' => [ 'restApiRoutes' => [
'/wc/store' => array_keys( \Automattic\WooCommerce\Blocks\RestApi::get_routes_from_namespace( 'wc/store' ) ), '/wc/store' => array_keys( \Automattic\WooCommerce\Blocks\RestApi::get_routes_from_namespace( 'wc/store' ) ),
], ],

View File

@ -7,6 +7,8 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes; namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Package;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
/** /**
@ -44,6 +46,10 @@ class Cart extends AbstractBlock {
* @return string Rendered block type output. * @return string Rendered block type output.
*/ */
public function render( $attributes = array(), $content = '' ) { public function render( $attributes = array(), $content = '' ) {
$data_registry = Package::container()->get(
\Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class
);
$data_registry->add( 'shippingCountries', WC()->countries->get_shipping_countries() );
\Automattic\WooCommerce\Blocks\Assets::register_block_script( \Automattic\WooCommerce\Blocks\Assets::register_block_script(
$this->block_name . '-frontend', $this->block_name . '-frontend',
$this->block_name . '-block-frontend' $this->block_name . '-block-frontend'

View File

@ -7,6 +7,8 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes; namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Package;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
/** /**
@ -45,6 +47,11 @@ class Checkout extends AbstractBlock {
* @return string Rendered block type output. * @return string Rendered block type output.
*/ */
public function render( $attributes = array(), $content = '' ) { public function render( $attributes = array(), $content = '' ) {
$data_registry = Package::container()->get(
\Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class
);
$data_registry->add( 'allowedCountries', WC()->countries->get_allowed_countries() );
$data_registry->add( 'shippingCountries', WC()->countries->get_shipping_countries() );
\Automattic\WooCommerce\Blocks\Assets::register_block_script( $this->block_name . '-frontend', $this->block_name . '-block-frontend' ); \Automattic\WooCommerce\Blocks\Assets::register_block_script( $this->block_name . '-frontend', $this->block_name . '-block-frontend' );
return $content; return $content;
} }