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

Use the archive-product template to render product attributes pages #6776

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}