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

Commit

Permalink
Release: 10.4.3 (#9919)
Browse files Browse the repository at this point in the history
* Empty commit for release pull request

* Update Hero Product 3-split pattern image

* Update Banner Pattern To Replace Unsplash Image (#9760)

* Update Banner to replace Unsplash image.

Replaces the Unsplash image with a CCO licensed image from Pxhere. Also
updates the CTA button to link to the Shop page, by default.

* Remove extra padding from top of test column.

Vertical alignment was off on the text column due to 60px of top
padding. This aligns everythign, as expected.

* Update Chessboard pattern images (#9761)

* Updathe the Hero Product Split (#9762)

* Remove unused pattern image (#9763)

* Update Images for the Product Details Patterns (#9764)

* Update image for the Product Hero pattern.

Replace the Unsplash image with a CCO licensed image from Pxhere.

* Update images for Prod List Gallery Desc pattern

Replace the Unsplash image with a CCO licensed image from Pxhere for the
Product Listing with Gallery and Description pattern.

* Remove unneeded Unsplash images.

* Update copy for Prod Listing Gallery Desc pattern.

* Optimize new image exports.

* Update image for the Product Listing pattern.

Replace the Unsplash image with a CCO licensed image from Pxhere.

* Update images for Product Details pattern.

Replace the Unsplash images with CCO licensed images from Pxhere.

* Remove unneeded Unsplash image.

* Use Relative URLs for Images in the Product Listing Pattern

This commit replaces hardcoded URLs with dynamic ones for image placeholders in the `product-listing-with-gallery-and-description.php` pattern file.

- The `plugins_url()` function is now used to generate URLs, which correctly points to the images folder within the WooCommerce Blocks plugin directory. This approach provides better flexibility and portability since it doesn't rely on a specific domain or path. The `esc_url()` function is used to ensure the URL is safe to use in the HTML context.

- The change is made for a total of four images in the pattern.

---------

Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>

* Update/patterns featured category product collection (#9765)

* Update image for featured category focus pattern

* Update image for featured category cover image pattern

* Update images for featured category triple pattern

* Change to wide width

* Update links to buttons

* Fix typo in hex color value.

There was an extra `f` in the hex color value, causing the text to
unexpectedly render black.

---------

Co-authored-by: Daniel W. Robert <danielwrobert@gmail.com>

* Update/collection pattern images (#9766)

* Update featured collections images

* Add shop link to shop by price pattern

* Update hero product pattern title (#9769)

* Remove unused pattern image (#9770)

* Add 10.4.2 changelog in readme.txt

* Update version number to 10.4.2

* Add testing instructions for 10.4.2

* Add 9769 PR testing steps

* WooCommerce Classic Template block: Fix error on clearing customizations on Woo Templates (#9759)

* Fix Classic Template block error on clearing customizations on template

* Add link to issue in JS Doc

* Change the way of debug check of tests-mysql container (#9794)

* Add alt text to images used in patterns describing their purpose (#9788)

* Add alt text to images used in patterns describing their purpose

* Replace 1/3 notation with 1 out of 3, so it's better handled byt screen readers

* Update testing instructions to include 9759 PR

* Update zip to include 9759 PR

* Remove 9759 PR from testing instructions

* Mini Cart Block: show the total price, including tax, according to the option (#9878)

* Mini Cart Block: show the total price, including tax, according to the option

* Fix tests in PR 9878 (#9880)

* add unit test

---------

Co-authored-by: Karol Manijak <karol.manijak@automattic.com>

* Mini-Cart: don't include shipping price (#9914)

* Products Block: fix grid view with Gutenberg 16 (#9916)

* Revert "fix products block layout on gutenberg 16 (#9886)"

This reverts commit f1e5dd7.

* add post_template_has_support_for_grid_view setting

* add testing instructions

* bump version

* update zip link

* Empty commit for release pull request

* update link

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
Co-authored-by: Daniel W. Robert <danielwrobert@users.noreply.github.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
Co-authored-by: Roy Ho <roykho77@gmail.com>
Co-authored-by: Daniel W. Robert <danielwrobert@gmail.com>
Co-authored-by: Tarun Vijwani <tarun.vijwani@automattic.com>
Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
Co-authored-by: Karol Manijak <karol.manijak@automattic.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
  • Loading branch information
13 people authored Jun 21, 2023
1 parent 63def1f commit 532fb99
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 23 deletions.
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.2",
"version": "10.4.3",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
36 changes: 36 additions & 0 deletions docs/internal-developers/testing/releases/1043.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Testing notes and ZIP for release 10.4.3

Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/11801978/woocommerce-gutenberg-products-block.zip)

## WooCommerce Core

### Products block: fix compatibility with Gutenberg 16. ([9916](https://github.com/woocommerce/woocommerce-blocks/pull/9916))

1. Ensure that you have Gutenberg 16 installed and enabled.
2. Open the post/page editor.
3. Add the Products Block.
4. Ensure that the Products Block defaults to the grid layout.

### Mini Cart Block: show the total price, including tax, according to the option. ([9878](https://github.com/woocommerce/woocommerce-blocks/pull/9878))

1. Open the WooCommerce Settings via WooCommerce > Settings from the sidebar menu of the WP-Admin.
2. Enable the option "Enable tax rates and calculations".
3. Click on the "Tax" tab.
4. Click on "Standard Rates" and configure a tax rate. Save.
5. Click on the "Tax" tab.
6. Set the "Display prices during cart and checkout" option to "Including Tax".
7. Now set up a Shipping method going to WooCommerce > Settings > Shipping > Add shipping zone. Create the zone and add a shipping method with a price different from 0.
8. With the Site Editor adds the Mini Cart in the header.
9. On the front end, add a product to the cart and go to the Cart page, so shipping price is calculated.
10. Go back to the Shop page
11. Ensure that the Mini Cart shows the price including the tax, but not including the Shipping prive.
12. Hover the Mini Cart.
13. Ensure that the Mini Cart shows always the same price.
14. Open the WooCommerce Settings.
15. Click on the "Tax" tab.
16. Set the "Display prices during cart and checkout" option to "Excluding Tax".
17. On the front end, add a product to the cart.
18. Refresh the page.
19. Ensure that the Mini Cart shows the price excluding the tax.
20. Hover the Mini Cart.
21. Ensure that the Mini Cart shows always the same price.
4 changes: 3 additions & 1 deletion docs/internal-developers/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ Every release includes specific testing instructions for new features and bug fi
- [10.2.2](./1022.md)
- [10.3.0](./1030.md)
- [10.4.0](./1040.md)
- [10.4.2](./1042.md)
- [10.4.2](./1042.md)
- [10.4.3](./1043.md)

<!-- FEEDBACK -->

---
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
"version": "10.4.2",
"version": "10.4.3",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 6.2
Tested up to: 6.2
Requires PHP: 7.3
Stable tag: 10.4.2
Stable tag: 10.4.3
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -81,6 +81,12 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/

== Changelog ==

= 10.4.3 - 2023-06-20 =

#### Bug Fixes

- Products block: fix compatibility with Gutenberg 16. ([9878](https://github.com/woocommerce/woocommerce-blocks/pull/9878))

= 10.4.2 - 2023-06-12 =

#### Bug Fixes
Expand Down
32 changes: 32 additions & 0 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@ protected function initialize() {
add_filter( 'rest_product_collection_params', array( $this, 'extend_rest_query_allowed_params' ), 10, 1 );
}

/**
* 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 );

$gutenberg_version = '';

if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
if ( defined( 'GUTENBERG_VERSION' ) ) {
$gutenberg_version = GUTENBERG_VERSION;
}

if ( ! $gutenberg_version ) {
$gutenberg_data = get_file_data(
WP_PLUGIN_DIR . '/gutenberg/gutenberg.php',
array( 'Version' => 'Version' )
);
$gutenberg_version = $gutenberg_data['Version'];
}
}

$this->asset_data_registry->add(
'post_template_has_support_for_grid_view',
version_compare( $gutenberg_version, '16.0', '>=' )
);
}

/**
* Check if a given block
*
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '10.4.2';
$version = '10.4.3';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
Loading

0 comments on commit 532fb99

Please sign in to comment.