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

Commit

Permalink
Use the archive-product template to render product attributes pages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin authored Jul 28, 2022
1 parent f11f11c commit b446a37
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ public function render_block_template() {
$this->block_template_is_available( 'taxonomy-product_tag' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} elseif ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) &&
! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
$this->block_template_is_available( 'archive-product' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} elseif (
( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
Expand Down
8 changes: 8 additions & 0 deletions src/Domain/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Automattic\WooCommerce\Blocks\Registry\Container;
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
use Automattic\WooCommerce\StoreApi\StoreApi;
use Automattic\WooCommerce\StoreApi\RoutesController;
use Automattic\WooCommerce\StoreApi\SchemaController;
Expand Down Expand Up @@ -116,6 +117,7 @@ function() {
$this->container->get( BlockTypesController::class );
$this->container->get( BlockTemplatesController::class );
$this->container->get( ProductSearchResultsTemplate::class );
$this->container->get( ProductAttributeTemplate::class );
$this->container->get( ClassicTemplatesCompatibility::class );
if ( $this->package->feature()->is_feature_plugin_build() ) {
$this->container->get( PaymentsApi::class );
Expand Down Expand Up @@ -249,6 +251,12 @@ function () {
return new ProductSearchResultsTemplate();
}
);
$this->container->register(
ProductAttributeTemplate::class,
function () {
return new ProductAttributeTemplate();
}
);
$this->container->register(
ClassicTemplatesCompatibility::class,
function ( Container $container ) {
Expand Down
39 changes: 39 additions & 0 deletions src/Templates/ProductAttributeTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Automattic\WooCommerce\Blocks\Templates;

/**
* ProductAttributeTemplate class.
*
* @internal
*/
class ProductAttributeTemplate {
const SLUG = 'archive-product';

/**
* Constructor.
*/
public function __construct() {
$this->init();
}

/**
* Initialization method.
*/
protected function init() {
add_filter( 'taxonomy_template_hierarchy', array( $this, 'update_taxonomy_template_hierarchy' ), 10, 3 );
}

/**
* Render the Archive Product Template for product attributes.
*
* @param array $templates Templates that match the product attributes taxonomy.
*/
public function update_taxonomy_template_hierarchy( $templates ) {
if ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) && wc_current_theme_is_fse_theme() ) {
array_unshift( $templates, self::SLUG );
}

return $templates;
}
}

0 comments on commit b446a37

Please sign in to comment.