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

Release: 10.4.3 #9919

Merged
merged 32 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aaffa31
Empty commit for release pull request
invalid-email-address Jun 12, 2023
f40145a
Update Hero Product 3-split pattern image
albarin Jun 8, 2023
3048367
Update Banner Pattern To Replace Unsplash Image (#9760)
danielwrobert Jun 8, 2023
2198599
Update Chessboard pattern images (#9761)
albarin Jun 8, 2023
9146775
Updathe the Hero Product Split (#9762)
albarin Jun 8, 2023
820e932
Remove unused pattern image (#9763)
albarin Jun 8, 2023
96a90c7
Update Images for the Product Details Patterns (#9764)
danielwrobert Jun 9, 2023
284ecb0
Update/patterns featured category product collection (#9765)
roykho Jun 9, 2023
4662d8e
Update/collection pattern images (#9766)
roykho Jun 9, 2023
96ff235
Update hero product pattern title (#9769)
albarin Jun 9, 2023
2b2b759
Remove unused pattern image (#9770)
albarin Jun 9, 2023
4b11102
Merge remote-tracking branch 'origin/release/10.4.2' into release/10.4.2
Jun 12, 2023
f5e7e35
Add 10.4.2 changelog in readme.txt
Jun 12, 2023
5caeb34
Update version number to 10.4.2
Jun 12, 2023
03fd9ae
Add testing instructions for 10.4.2
Jun 12, 2023
3b66f89
Add 9769 PR testing steps
Jun 12, 2023
cc57b39
WooCommerce Classic Template block: Fix error on clearing customizati…
thealexandrelara Jun 12, 2023
9748294
Change the way of debug check of tests-mysql container (#9794)
kmanijak Jun 12, 2023
4be8e42
Add alt text to images used in patterns describing their purpose (#9788)
kmanijak Jun 12, 2023
1ea18c9
Update testing instructions to include 9759 PR
Jun 13, 2023
695197e
Update zip to include 9759 PR
Jun 13, 2023
2886a75
Remove 9759 PR from testing instructions
Jun 13, 2023
d27f7e7
Mini Cart Block: show the total price, including tax, according to th…
gigitux Jun 19, 2023
b62828c
Mini-Cart: don't include shipping price (#9914)
Aljullu Jun 20, 2023
1b7a4b9
Products Block: fix grid view with Gutenberg 16 (#9916)
gigitux Jun 20, 2023
4e94595
add testing instructions
gigitux Jun 20, 2023
5f07888
bump version
gigitux Jun 20, 2023
c3ac250
update zip link
gigitux Jun 20, 2023
57b08ad
Empty commit for release pull request
invalid-email-address Jun 20, 2023
02efbfe
update link
gigitux Jun 20, 2023
1e97d1d
Merge branch 'release/10.4.3' of https://github.com/woocommerce/wooco…
gigitux Jun 20, 2023
e49ebe0
Merge branch 'release/10.4.0' of https://github.com/woocommerce/wooco…
gigitux Jun 21, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:

- name: Docker container debug information
run: |
npm run wp-env run tests-mysql "mysql --version"
npm run wp-env run tests-mysql mysql -- --version
npm run wp-env run tests-wordpress "php --version"
npm run wp-env run tests-wordpress "php -m"
npm run wp-env run tests-wordpress "php -i"
Expand Down
71 changes: 62 additions & 9 deletions assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getBlockType,
registerBlockType,
unregisterBlockType,
parse,
} from '@wordpress/blocks';
import type { BlockEditProps } from '@wordpress/blocks';
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';
Expand All @@ -18,10 +19,17 @@ import {
import { Button, Placeholder, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { box, Icon } from '@wordpress/icons';
import { useDispatch, subscribe, useSelect, select } from '@wordpress/data';
import {
useDispatch,
subscribe,
useSelect,
select,
dispatch,
} from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { useEntityRecord } from '@wordpress/core-data';
import { debounce } from '@woocommerce/base-utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -333,6 +341,44 @@ const registerClassicTemplateBlock = ( {
} );
};

/**
* Attempts to recover the Classic Template block if it fails to render on the Single Product template
* due to the user resetting customizations without refreshing the page.
*
* When the Classic Template block fails to render, it is replaced by the 'core/missing' block, which
* displays an error message stating that the WooCommerce Classic template block is unsupported.
*
* This function replaces the 'core/missing' block with the original Classic Template block that failed
* to render, allowing the block to be displayed correctly.
*
* @see {@link https://github.com/woocommerce/woocommerce-blocks/issues/9637|Issue: Block error is displayed on clearing customizations for Woo Templates}
*
*/
const tryToRecoverClassicTemplateBlockWhenItFailsToRender = debounce( () => {
const blocks = select( 'core/block-editor' ).getBlocks();
const blocksIncludingInnerBlocks = blocks.flatMap( ( block ) => [
block,
...block.innerBlocks,
] );
const classicTemplateThatFailedToRender = blocksIncludingInnerBlocks.find(
( block ) =>
block.name === 'core/missing' &&
block.attributes.originalName === BLOCK_SLUG
);

if ( classicTemplateThatFailedToRender ) {
const blockToReplaceClassicTemplateBlockThatFailedToRender = parse(
classicTemplateThatFailedToRender.attributes.originalContent
);
if ( blockToReplaceClassicTemplateBlockThatFailedToRender ) {
dispatch( 'core/block-editor' ).replaceBlock(
classicTemplateThatFailedToRender.clientId,
blockToReplaceClassicTemplateBlockThatFailedToRender
);
}
}
}, 100 );

// @todo Refactor when there will be possible to show a block according on a template/post with a Gutenberg API. https://github.com/WordPress/gutenberg/pull/41718

let currentTemplateId: string | undefined;
Expand All @@ -341,21 +387,28 @@ subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
currentTemplateId = store?.getEditedPostId() as string | undefined;

if ( previousTemplateId === currentTemplateId ) {
return;
}

const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];

if ( parsedTemplate === null || parsedTemplate === undefined ) {
return;
}

const block = getBlockType( BLOCK_SLUG );
const isBlockRegistered = Boolean( block );

if (
isBlockRegistered &&
hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES )
) {
tryToRecoverClassicTemplateBlockWhenItFailsToRender();
}

if ( previousTemplateId === currentTemplateId ) {
return;
}

if (
block !== undefined &&
isBlockRegistered &&
( ! hasTemplateSupportForClassicTemplateBlock(
parsedTemplate,
TEMPLATES
Expand All @@ -371,12 +424,12 @@ subscribe( () => {
}

if (
block === undefined &&
! isBlockRegistered &&
hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES )
) {
registerClassicTemplateBlock( {
template: parsedTemplate,
inserter: true,
} );
}
} );
}, 'core/blocks-editor' );
33 changes: 24 additions & 9 deletions assets/js/blocks/mini-cart/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ import {
getCurrencyFromPriceResponse,
formatPrice,
} from '@woocommerce/price-format';
import { CartResponse } from '@woocommerce/types';
import { CartResponse, isBoolean } from '@woocommerce/types';
import { getSettingWithCoercion } from '@woocommerce/settings';

const getPrice = ( cartResponse: CartResponse, showIncludingTax: boolean ) => {
const { totals } = cartResponse;
const currency = getCurrencyFromPriceResponse( totals );

const subTotal = showIncludingTax
? parseInt( totals.total_items, 10 ) +
parseInt( totals.total_items_tax, 10 )
: parseInt( totals.total_items, 10 );

return formatPrice( subTotal, currency );
};

export const updateTotals = ( totals: [ string, number ] | undefined ) => {
if ( ! totals ) {
Expand Down Expand Up @@ -86,11 +99,12 @@ export const getMiniCartTotalsFromLocalStorage = ():
return undefined;
}
const miniCartTotals = JSON.parse( rawMiniCartTotals );
const currency = getCurrencyFromPriceResponse( miniCartTotals.totals );
const formattedPrice = formatPrice(
miniCartTotals.totals.total_price,
currency
const showIncludingTax = getSettingWithCoercion(
'displayCartPricesIncludingTax',
false,
isBoolean
);
const formattedPrice = getPrice( miniCartTotals, showIncludingTax );
return [ formattedPrice, miniCartTotals.itemsCount ] as [ string, number ];
};

Expand All @@ -107,11 +121,12 @@ export const getMiniCartTotalsFromServer = async (): Promise<
return response.json();
} )
.then( ( data: CartResponse ) => {
const currency = getCurrencyFromPriceResponse( data.totals );
const formattedPrice = formatPrice(
data.totals.total_price,
currency
const showIncludingTax = getSettingWithCoercion(
'displayCartPricesIncludingTax',
false,
isBoolean
);
const formattedPrice = getPrice( data, showIncludingTax );
// Save server data to local storage, so we can re-fetch it faster
// on the next page load.
localStorage.setItem(
Expand Down
87 changes: 84 additions & 3 deletions assets/js/blocks/mini-cart/utils/test/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
import { getByTestId, waitFor } from '@testing-library/dom';
import { getSettingWithCoercion } from '@woocommerce/settings';

/**
* Internal dependencies
Expand All @@ -18,7 +19,9 @@ const responseMock = {
ok: true,
json: async () => ( {
totals: {
total_price: '1600',
total_price: '1800',
total_items: '1400',
total_items_tax: '200',
currency_code: 'USD',
currency_symbol: '$',
currency_minor_unit: 2,
Expand All @@ -32,7 +35,9 @@ const responseMock = {
} as Response;
const localStorageMock = {
totals: {
total_price: '1600',
total_price: '1800',
total_items: '1400',
total_items_tax: '200',
currency_code: 'USD',
currency_symbol: '$',
currency_minor_unit: 2,
Expand Down Expand Up @@ -67,7 +72,21 @@ const getMiniCartDOM = () => {
return div;
};

describe( 'Mini-Cart frontend script', () => {
jest.mock( '@woocommerce/settings', () => {
return {
...jest.requireActual( '@woocommerce/settings' ),
getSettingWithCoercion: jest.fn(),
};
} );

describe( 'Mini-Cart frontend script when "the display prices during cart and checkout" option is set to "Including Tax"', () => {
beforeAll( () => {
( getSettingWithCoercion as jest.Mock ).mockReturnValue( true );
} );

afterAll( () => {
jest.resetModules();
} );
it( 'updates the cart contents based on the localStorage values', async () => {
initializeLocalStorage();
const container = getMiniCartDOM();
Expand Down Expand Up @@ -125,3 +144,65 @@ describe( 'Mini-Cart frontend script', () => {
jest.restoreAllMocks();
} );
} );

describe( 'Mini-Cart frontend script when "the display prices during cart and checkout" option is set to "Excluding Tax"', () => {
beforeAll( () => {
( getSettingWithCoercion as jest.Mock ).mockReturnValue( false );
} );
it( 'updates the cart contents based on the localStorage values', async () => {
initializeLocalStorage();
const container = getMiniCartDOM();
document.body.appendChild( container );

updateTotals( getMiniCartTotalsFromLocalStorage() );

// Assert that we are rendering the amount.
await waitFor( () =>
expect( getByTestId( container, 'amount' ).textContent ).toBe(
'$14.00'
)
);
// Assert that we are rendering the quantity.
await waitFor( () =>
expect( getByTestId( container, 'quantity' ).textContent ).toBe(
'2'
)
);
} );

it( 'updates the cart contents based on the API response', async () => {
jest.spyOn( window, 'fetch' ).mockResolvedValue( responseMock );
const container = getMiniCartDOM();
document.body.appendChild( container );

getMiniCartTotalsFromServer().then( updateTotals );

// Assert we called the correct endpoint.
await waitFor( () =>
expect( window.fetch ).toHaveBeenCalledWith(
'/wp-json/wc/store/v1/cart/'
)
);

// Assert we saved the values returned to the localStorage.
await waitFor( () =>
expect( window.localStorage.setItem.mock.calls[ 0 ][ 1 ] ).toEqual(
JSON.stringify( localStorageMock )
)
);

// Assert that we are rendering the amount.
await waitFor( () =>
expect( getByTestId( container, 'amount' ).textContent ).toBe(
'$14.00'
)
);
// Assert that we are rendering the quantity.
await waitFor( () =>
expect( getByTestId( container, 'quantity' ).textContent ).toBe(
'2'
)
);
jest.restoreAllMocks();
} );
} );
14 changes: 12 additions & 2 deletions assets/js/blocks/product-query/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* External dependencies
*/
import { getSetting } from '@woocommerce/settings';
import { getSetting, getSettingWithCoercion } from '@woocommerce/settings';
import { objectOmit } from '@woocommerce/utils';
import type { InnerBlockTemplate } from '@wordpress/blocks';

import { isBoolean } from '@woocommerce/types';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -69,6 +69,13 @@ export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = {
},
};

// This is necessary to fix https://github.com/woocommerce/woocommerce-blocks/issues/9884.
const postTemplateHasSupportForGridView = getSettingWithCoercion(
'post_template_has_support_for_grid_view',
false,
isBoolean
);

export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
[
'core/post-template',
Expand All @@ -78,6 +85,9 @@ export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
* This class is used to add default styles for inner blocks.
*/
className: 'products-block-post-template',
...( postTemplateHasSupportForGridView && {
layout: { type: 'grid', columnCount: 3 },
} ),
},
[
[
Expand Down
15 changes: 14 additions & 1 deletion assets/js/blocks/product-query/variations/related-products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Icon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { stacks } from '@woocommerce/icons';
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
import { getSettingWithCoercion } from '@woocommerce/settings';
import { isBoolean } from '@woocommerce/types';

/**
* Internal dependencies
Expand Down Expand Up @@ -43,6 +45,12 @@ export const BLOCK_ATTRIBUTES = {
},
};

const postTemplateHasSupportForGridView = getSettingWithCoercion(
'post_template_has_support_for_grid_view',
false,
isBoolean
);

export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
[
'core/heading',
Expand All @@ -53,7 +61,12 @@ export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
],
[
'core/post-template',
{ __woocommerceNamespace: PRODUCT_TEMPLATE_ID },
{
__woocommerceNamespace: PRODUCT_TEMPLATE_ID,
...( postTemplateHasSupportForGridView && {
layout: { type: 'grid', columnCount: 3 },
} ),
},
[
[
'woocommerce/product-image',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://woocommerce.com/",
"type": "wordpress-plugin",
"version": "10.4.0",
"version": "10.4.3",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
Loading