Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Feb 22, 2024
1 parent bc8d0c9 commit 5a464fc
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 39 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ public static function register_templates() {
OrderConfirmationTemplate::SLUG => new OrderConfirmationTemplate(),
SingleProductTemplate::SLUG => new SingleProductTemplate(),
);
} else {
$templates = array();
}
if ( BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) {
$template_parts = array(
MiniCartTemplate::SLUG => new MiniCartTemplate(),
CheckoutHeaderTemplate::SLUG => new CheckoutHeaderTemplate(),
);
} else {
$template_parts = array();
}
self::$templates = array_merge( $templates, $template_parts );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract protected function is_active_template();
*/
public function page_template_hierarchy( $templates ) {
if ( $this->is_active_template() ) {
array_unshift( $templates, self::SLUG );
array_unshift( $templates, static::SLUG );
}
return $templates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,4 @@ abstract class AbstractTemplatePart extends AbstractTemplate {
* @var string
*/
public static $template_area;

/**
* Constructor.
*/
public function __construct() {
$this->init();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Automattic\WooCommerce\Blocks\Templates;

use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;

/**
* OrderConfirmationTemplate class.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Automattic\WooCommerce\Blocks\Templates;

use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static function get_block_template_area( $template_slug, $template_type )
if ( 'wp_template_part' === $template_type ) {
$registered_template = BlockTemplatesRegistry::get_template( $template_slug );
if ( $registered_template && property_exists( $registered_template, 'template_area' ) ) {
return $registered_template->template_area;
return $registered_template::$template_area;
}
}
return 'uncategorized';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
use Automattic\WooCommerce\Blocks\Options;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductCategoryTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductTagTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplate;
use Automattic\WooCommerce\Blocks\BlockTemplatesController;
use WP_UnitTestCase;

/**
Expand All @@ -33,8 +29,8 @@ protected function setUp(): void {

// Switch to a block theme and register templates.
$this->container = Package::container();
$this->container->get( BlockTemplatesController::class );
switch_theme( 'twentytwentytwo' );
$this->register_block_templates();

// Reset options.
delete_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE );
Expand All @@ -53,27 +49,6 @@ public function provideFallbackData() {
);
}

/**
* Constructs template classes. Needed so template are registered after
* switching to a block theme.
*
* @return void
*/
public function register_block_templates(): void {
$templates = [
ProductCatalogTemplate::class,
ProductCategoryTemplate::class,
ProductTagTemplate::class,
ProductAttributeTemplate::class,
SingleProductTemplate::class,
];

foreach ( $templates as $template_class ) {
$template = $this->container->get( $template_class );
$template->__construct();
}
}

/**
* Test template_is_eligible_for_product_archive_fallback.
*
Expand Down

0 comments on commit 5a464fc

Please sign in to comment.