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

Commit

Permalink
Fix All Products Block Tests due to incorrect Stock Filter addition (#…
Browse files Browse the repository at this point in the history
…5541)

* Remove stock filter from all products block

* Add missing stock filter to product-category block
  • Loading branch information
mikejolley authored Jan 11, 2022
1 parent aa78099 commit de7d7a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 71 deletions.
14 changes: 14 additions & 0 deletions assets/js/blocks/product-category/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import GridContentControl from '@woocommerce/editor-components/grid-content-cont
import GridLayoutControl from '@woocommerce/editor-components/grid-layout-control';
import ProductCategoryControl from '@woocommerce/editor-components/product-category-control';
import ProductOrderbyControl from '@woocommerce/editor-components/product-orderby-control';
import ProductStockControl from '@woocommerce/editor-components/product-stock-control';
import { gridBlockPreview } from '@woocommerce/resource-previews';
import { Icon, folder } from '@woocommerce/icons';
import { getSetting } from '@woocommerce/settings';
Expand Down Expand Up @@ -119,6 +120,7 @@ class ProductByCategoryBlock extends Component {
orderby,
rows,
alignButtons,
stockStatus,
} = attributes;

return (
Expand Down Expand Up @@ -186,6 +188,18 @@ class ProductByCategoryBlock extends Component {
value={ orderby }
/>
</PanelBody>
<PanelBody
title={ __(
'Stock level',
'woo-gutenberg-products-block'
) }
initialOpen={ false }
>
<ProductStockControl
setAttributes={ setAttributes }
value={ stockStatus }
/>
</PanelBody>
</InspectorControls>
);
}
Expand Down
9 changes: 0 additions & 9 deletions assets/js/blocks/products/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const defaults = {
orderby: 'date',
layoutConfig: DEFAULT_PRODUCT_LIST_LAYOUT,
isPreview: false,
stockStatus: 'any',
};

export const attributes = {
Expand Down Expand Up @@ -65,12 +64,4 @@ export const attributes = {
type: 'boolean',
default: false,
},

/**
* Whether to display in stock, out of stock or backorder products.
*/
stockStatus: {
type: 'string',
default: 'any',
},
};
106 changes: 44 additions & 62 deletions assets/js/blocks/products/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody, ToggleControl, SelectControl } from '@wordpress/components';
import ProductStockControl from '@woocommerce/editor-components/product-stock-control';
import { ToggleControl, SelectControl } from '@wordpress/components';

export const getSharedContentControls = ( attributes, setAttributes ) => {
const { contentVisibility } = attributes;
Expand All @@ -28,65 +27,48 @@ export const getSharedContentControls = ( attributes, setAttributes ) => {

export const getSharedListControls = ( attributes, setAttributes ) => {
return (
<div>
<SelectControl
label={ __(
'Order Products By',
'woo-gutenberg-products-block'
) }
value={ attributes.orderby }
options={ [
{
label: __(
'Default sorting (menu order)',
'woo-gutenberg-products-block'
),
value: 'menu_order',
},
{
label: __(
'Popularity',
'woo-gutenberg-products-block'
),
value: 'popularity',
},
{
label: __(
'Average rating',
'woo-gutenberg-products-block'
),
value: 'rating',
},
{
label: __( 'Latest', 'woo-gutenberg-products-block' ),
value: 'date',
},
{
label: __(
'Price: low to high',
'woo-gutenberg-products-block'
),
value: 'price',
},
{
label: __(
'Price: high to low',
'woo-gutenberg-products-block'
),
value: 'price-desc',
},
] }
onChange={ ( orderby ) => setAttributes( { orderby } ) }
/>
<PanelBody
title={ __( 'Stock level', 'woo-gutenberg-products-block' ) }
initialOpen={ false }
>
<ProductStockControl
setAttributes={ setAttributes }
value={ attributes.stockStatus }
/>
</PanelBody>
</div>
<SelectControl
label={ __( 'Order Products By', 'woo-gutenberg-products-block' ) }
value={ attributes.orderby }
options={ [
{
label: __(
'Default sorting (menu order)',
'woo-gutenberg-products-block'
),
value: 'menu_order',
},
{
label: __( 'Popularity', 'woo-gutenberg-products-block' ),
value: 'popularity',
},
{
label: __(
'Average rating',
'woo-gutenberg-products-block'
),
value: 'rating',
},
{
label: __( 'Latest', 'woo-gutenberg-products-block' ),
value: 'date',
},
{
label: __(
'Price: low to high',
'woo-gutenberg-products-block'
),
value: 'price',
},
{
label: __(
'Price: high to low',
'woo-gutenberg-products-block'
),
value: 'price-desc',
},
] }
onChange={ ( orderby ) => setAttributes( { orderby } ) }
/>
);
};

0 comments on commit de7d7a8

Please sign in to comment.