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

Set inherit setting to true when is inserted in the archive product template #8251

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion assets/js/blocks/product-query/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const GLOBAL_HIDE_OUT_OF_STOCK = getSetting< boolean >(
false
);

const isArchiveProductTemplate = getSetting< boolean >(
'is_archive_product_template',
false
);

export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = {
allowedControls: DEFAULT_ALLOWED_CONTROLS,
displayLayout: {
Expand All @@ -64,7 +69,7 @@ export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = {
search: '',
exclude: [],
sticky: '',
inherit: false,
inherit: isArchiveProductTemplate,
__woocommerceAttributes: [],
__woocommerceStockStatus: GLOBAL_HIDE_OUT_OF_STOCK
? Object.keys( objectOmit( STOCK_STATUS_OPTIONS, 'outofstock' ) )
Expand Down
17 changes: 17 additions & 0 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ public function update_query( $pre_render, $parsed_block ) {
}
}

/**
* Extra data passed through from server to client for block.
*
* @param array $attributes Any attributes that currently are available from the block.
* Note, this will be empty in the editor context when the block is
* not in the post content on editor load.
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );

global $pagenow;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_id = isset( $_GET['postId'] ) ? sanitize_text_field( wp_unslash( $_GET['postId'] ) ) : null;
$is_archive_product_template = 'site-editor.php' === $pagenow && 'woocommerce/woocommerce//archive-product' === $post_id;
$this->asset_data_registry->add( 'is_archive_product_template', $is_archive_product_template, true );
}

/**
* Update the query for the product query block in Editor.
*
Expand Down