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

Commit

Permalink
Set inherit default to true only when is inserted in the archive prod…
Browse files Browse the repository at this point in the history
…uct template (#8251)
  • Loading branch information
albarin authored Jan 24, 2023
1 parent 1810a9a commit 39b0f91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 39b0f91

Please sign in to comment.