2022-09-01 13:13:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-01-05 21:23:34 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2023-05-08 12:50:10 +00:00
|
|
|
import { objectOmit } from '@woocommerce/utils';
|
2022-09-23 13:07:44 +00:00
|
|
|
import type { InnerBlockTemplate } from '@wordpress/blocks';
|
2022-09-01 13:13:19 +00:00
|
|
|
|
2022-08-18 08:02:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-09-23 13:07:44 +00:00
|
|
|
import { QueryBlockAttributes } from './types';
|
2022-12-05 15:56:53 +00:00
|
|
|
import { VARIATION_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
2022-12-30 15:51:27 +00:00
|
|
|
import { VARIATION_NAME as PRODUCT_TEMPLATE_ID } from './variations/elements/product-template';
|
2023-04-11 14:41:34 +00:00
|
|
|
import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
|
2022-08-18 08:02:21 +00:00
|
|
|
|
2023-03-08 16:22:51 +00:00
|
|
|
export const EDIT_ATTRIBUTES_URL =
|
|
|
|
'/wp-admin/edit.php?post_type=product&page=product_attributes';
|
|
|
|
|
2022-10-27 17:40:10 +00:00
|
|
|
export const QUERY_LOOP_ID = 'core/query';
|
|
|
|
|
2022-11-21 18:21:58 +00:00
|
|
|
export const DEFAULT_CORE_ALLOWED_CONTROLS = [ 'taxQuery', 'search' ];
|
2022-09-23 13:07:44 +00:00
|
|
|
|
2022-11-21 18:21:58 +00:00
|
|
|
export const ALL_PRODUCT_QUERY_CONTROLS = [
|
2022-11-29 13:44:52 +00:00
|
|
|
'attributes',
|
2022-11-21 18:21:58 +00:00
|
|
|
'presets',
|
2023-05-08 12:50:10 +00:00
|
|
|
'productSelector',
|
2022-11-21 18:21:58 +00:00
|
|
|
'onSale',
|
|
|
|
'stockStatus',
|
2022-12-12 15:06:25 +00:00
|
|
|
'wooInherit',
|
2022-11-21 18:21:58 +00:00
|
|
|
];
|
2022-09-23 13:07:44 +00:00
|
|
|
|
|
|
|
export const DEFAULT_ALLOWED_CONTROLS = [
|
|
|
|
...DEFAULT_CORE_ALLOWED_CONTROLS,
|
|
|
|
...ALL_PRODUCT_QUERY_CONTROLS,
|
|
|
|
];
|
|
|
|
|
2022-10-27 17:40:10 +00:00
|
|
|
export const STOCK_STATUS_OPTIONS = getSetting< Record< string, string > >(
|
|
|
|
'stockStatusOptions',
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const GLOBAL_HIDE_OUT_OF_STOCK = getSetting< boolean >(
|
|
|
|
'hideOutOfStockItems',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2022-09-23 13:07:44 +00:00
|
|
|
export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = {
|
2022-10-11 14:04:54 +00:00
|
|
|
allowedControls: DEFAULT_ALLOWED_CONTROLS,
|
2022-09-01 13:13:19 +00:00
|
|
|
displayLayout: {
|
|
|
|
type: 'flex',
|
|
|
|
columns: 3,
|
|
|
|
},
|
2022-08-18 08:02:21 +00:00
|
|
|
query: {
|
2022-12-05 12:46:50 +00:00
|
|
|
perPage: 9,
|
2022-08-18 08:02:21 +00:00
|
|
|
pages: 0,
|
|
|
|
offset: 0,
|
|
|
|
postType: 'product',
|
2022-12-12 15:06:25 +00:00
|
|
|
order: 'asc',
|
|
|
|
orderBy: 'title',
|
2022-08-18 08:02:21 +00:00
|
|
|
author: '',
|
|
|
|
search: '',
|
|
|
|
exclude: [],
|
|
|
|
sticky: '',
|
2023-02-01 12:48:17 +00:00
|
|
|
inherit: false,
|
2022-11-29 13:44:52 +00:00
|
|
|
__woocommerceAttributes: [],
|
2022-10-27 17:40:10 +00:00
|
|
|
__woocommerceStockStatus: GLOBAL_HIDE_OUT_OF_STOCK
|
|
|
|
? Object.keys( objectOmit( STOCK_STATUS_OPTIONS, 'outofstock' ) )
|
|
|
|
: Object.keys( STOCK_STATUS_OPTIONS ),
|
2022-08-18 08:02:21 +00:00
|
|
|
},
|
|
|
|
};
|
2022-09-01 13:13:19 +00:00
|
|
|
|
|
|
|
export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
|
|
|
|
[
|
|
|
|
'core/post-template',
|
Products block: Using nested selector to add margin between Product elements (https://github.com/woocommerce/woocommerce-blocks/pull/8993)
* Using nested selector to style Product elements in Products Block
This commit simplifies the INNER_BLOCKS_TEMPLATE array in the product-query constants.ts file by removing the style properties from the individual elements. Instead, the default styles are now managed in the style.scss file, providing a more consistent and centralized approach to styling.
In the style.scss file, a new section for default styling has been added to handle product elements inside the Products Block, adhering to the Gutenberg styling hierarchy. This ensures the lowest precedence in the hierarchy, allowing for easier overrides when needed.
* Decrease specificity of styles for product elements in Products Block
The commit changes the default styles for product elements inside the 'Products Block'. It changes the way the margin-bottom and margin-top properties are set by using the :where() selector instead of using the .products-block-post-template class selector. This is done to decrease the specificity of the CSS selector, ensuring that the styles have the lowest precedence in the hierarchy. It also removes the display: inline-block property from the a selector, and moves the styles to the .editor-styles-wrapper class selector.
* Decrease specificity of CSS selectors
In these changes, the product elements inside the Products Block have been restyled. The specificity of the CSS selector has been decreased using the :where() selector, to ensure that these styles have the lowest precedence in the hierarchy.
In constants.ts, a new class name, products-block-post-template, has been added to the inner block template for the post. This class is used to add default styles for inner blocks.
In style.scss, the CSS selector for the inner blocks has been updated to include the new class name. The :where() selector has also been used to ensure that these styles have the lowest precedence in the hierarchy.
* Update default margins and remove redundant entries
This commit updates the default margin values for the Product Title in the Products block, moving them from the style.scss file to the constants.ts file. It also removes unnecessary empty arrays in the INNER_BLOCKS_TEMPLATE and background-color property from the style.scss file.
2023-04-28 07:43:47 +00:00
|
|
|
{
|
|
|
|
__woocommerceNamespace: PRODUCT_TEMPLATE_ID,
|
2023-06-20 06:56:55 +00:00
|
|
|
layout: {
|
|
|
|
type: 'grid',
|
|
|
|
columnsCount: 3,
|
|
|
|
},
|
Products block: Using nested selector to add margin between Product elements (https://github.com/woocommerce/woocommerce-blocks/pull/8993)
* Using nested selector to style Product elements in Products Block
This commit simplifies the INNER_BLOCKS_TEMPLATE array in the product-query constants.ts file by removing the style properties from the individual elements. Instead, the default styles are now managed in the style.scss file, providing a more consistent and centralized approach to styling.
In the style.scss file, a new section for default styling has been added to handle product elements inside the Products Block, adhering to the Gutenberg styling hierarchy. This ensures the lowest precedence in the hierarchy, allowing for easier overrides when needed.
* Decrease specificity of styles for product elements in Products Block
The commit changes the default styles for product elements inside the 'Products Block'. It changes the way the margin-bottom and margin-top properties are set by using the :where() selector instead of using the .products-block-post-template class selector. This is done to decrease the specificity of the CSS selector, ensuring that the styles have the lowest precedence in the hierarchy. It also removes the display: inline-block property from the a selector, and moves the styles to the .editor-styles-wrapper class selector.
* Decrease specificity of CSS selectors
In these changes, the product elements inside the Products Block have been restyled. The specificity of the CSS selector has been decreased using the :where() selector, to ensure that these styles have the lowest precedence in the hierarchy.
In constants.ts, a new class name, products-block-post-template, has been added to the inner block template for the post. This class is used to add default styles for inner blocks.
In style.scss, the CSS selector for the inner blocks has been updated to include the new class name. The :where() selector has also been used to ensure that these styles have the lowest precedence in the hierarchy.
* Update default margins and remove redundant entries
This commit updates the default margin values for the Product Title in the Products block, moving them from the style.scss file to the constants.ts file. It also removes unnecessary empty arrays in the INNER_BLOCKS_TEMPLATE and background-color property from the style.scss file.
2023-04-28 07:43:47 +00:00
|
|
|
/**
|
|
|
|
* This class is used to add default styles for inner blocks.
|
|
|
|
*/
|
|
|
|
className: 'products-block-post-template',
|
|
|
|
},
|
2022-09-01 13:13:19 +00:00
|
|
|
[
|
2023-03-10 06:04:47 +00:00
|
|
|
[
|
|
|
|
'woocommerce/product-image',
|
|
|
|
{
|
2023-04-11 14:41:34 +00:00
|
|
|
imageSizing: ImageSizing.THUMBNAIL,
|
2023-03-10 06:04:47 +00:00
|
|
|
},
|
|
|
|
],
|
2022-09-01 13:13:19 +00:00
|
|
|
[
|
|
|
|
'core/post-title',
|
|
|
|
{
|
2022-12-05 12:46:50 +00:00
|
|
|
textAlign: 'center',
|
2022-09-01 13:13:19 +00:00
|
|
|
level: 3,
|
2022-12-05 12:46:50 +00:00
|
|
|
fontSize: 'medium',
|
2023-03-10 06:04:47 +00:00
|
|
|
style: {
|
|
|
|
spacing: {
|
|
|
|
margin: {
|
|
|
|
bottom: '0.75rem',
|
|
|
|
top: '0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-23 13:00:44 +00:00
|
|
|
isLink: true,
|
2022-12-05 15:56:53 +00:00
|
|
|
__woocommerceNamespace: PRODUCT_TITLE_ID,
|
2022-12-05 12:46:50 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'woocommerce/product-price',
|
2023-01-20 14:56:29 +00:00
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
fontSize: 'small',
|
|
|
|
},
|
2022-12-05 12:46:50 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'woocommerce/product-button',
|
2023-01-20 15:23:00 +00:00
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
fontSize: 'small',
|
|
|
|
},
|
2022-09-01 13:13:19 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2022-12-13 13:53:26 +00:00
|
|
|
[
|
|
|
|
'core/query-pagination',
|
|
|
|
{
|
|
|
|
layout: {
|
|
|
|
type: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2023-01-05 21:23:34 +00:00
|
|
|
[ 'core/query-no-results' ],
|
2022-09-01 13:13:19 +00:00
|
|
|
];
|