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

Display "Add review" link if there's no product rating #7929

Merged
merged 19 commits into from
Dec 28, 2022

Conversation

kmanijak
Copy link
Contributor

@kmanijak kmanijak commented Dec 13, 2022

This PR is repurposed based on the discussion in the comments.

TLDR:
Previously: Add 5 empty stars when there's no rating
Currently: Add "Add review" link to the products with no ratings
Reason for change: "Empty" stars could be interpreted as rating 0/5, which could give a false impression


Description

It was suggested within the scope of Product Query patterns to display something when there's no product ratings, so the layout is preserved.

This PR enables "Add review" link in:

  • All Products
  • Products
    in case there's no rating.

"Add review" link redirects to <<product_URL>>#reviews, so to the reviews section.

Previously there was no "loading" placeholder, since it wasn't determined if there will be any content rendered. Currently, as it's determined that either rating or a link will be rendered, the placeholder is visible during loading.

Fixes #7923

Accessibility

  • I've tested using only a keyboard (no mouse)
  • I've tested using a screen reader

Screenshots

Case Before After
Products (Editor) image image
Products (Frontend) image image
All Products (Editor) image image
All Products (Frontend) image image

Testing

User Facing Testing

Prerequisites:

  • make sure you have at least one product with and at least one product without rating
All Products and Products blocks

Steps:

  1. Go to Editor and add All Products block
  2. Make sure Rating is included in product layout (Pencil icon > Use inserter > Add "Product Rating" block)
  3. Save the template

Expected:

  • Both products, with and without rating, have the same layout.
  • Products with no rating have "Add review" link
  • Link is not clickable in Editor
  1. Go to the Frontend

Expected:

  • Both products, with and without rating, have the same layout.
  • Products with no rating have "Add review" link
  • Link is interactive and redirects to Review section of the product

Repeat the same for the Products block!

Regression testing - Product view
  1. Go to product page of the product without rating.

Expected:

  • There's no "Add review" link instead or rating stars
Regression testing - Rating alignment
  1. Check the Alignment settings in both: Products for both: stars and link!

image

Expected:

  • Alignment is respected in Editor and Frontend for all: left, center and right alignment
Regression testing - Filer by Rating
  1. Add Filter by Rating block
  2. Save and go to Frontend

Expected:

  • There's no "loading" placeholder in place of stars in the Filter by Rating

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Products and All Products: Display "Add review" link when there's no product rating

@woocommercebot woocommercebot requested review from a team and nefeline and removed request for a team December 13, 2022 11:50
@github-actions
Copy link
Contributor

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7929.zip

@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2022

TypeScript Errors Report

Files with errors: 431
Total errors: 2101

⚠️ ⚠️ This PR introduces new TS errors on 1 files:

assets/js/atomic/blocks/product-elements/rating/block.tsx

@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2022

Size Change: +782 B (0%)

Total Size: 1.01 MB

Filename Size Change
build/active-filters.js 7.32 kB +1 B (0%)
build/all-products.js 33.4 kB +109 B (0%)
build/all-reviews.js 7.65 kB -2 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 9.63 kB +98 B (+1%)
build/cart-frontend.js 28.1 kB -1 B (0%)
build/cart.js 46.4 kB +118 B (0%)
build/checkout.js 40.3 kB +5 B (0%)
build/featured-category.js 13.1 kB -2 B (0%)
build/featured-product.js 13.3 kB +1 B (0%)
build/filter-wrapper.js 2.4 kB -3 B (0%)
build/legacy-template.js 2.85 kB +2 B (0%)
build/mini-cart.js 4.26 kB -1 B (0%)
build/price-filter.js 8.38 kB +2 B (0%)
build/product-category.js 8.57 kB -2 B (0%)
build/product-image.js 3.94 kB +2 B (0%)
build/product-on-sale.js 7.9 kB +1 B (0%)
build/product-query.js 5.94 kB +1 B (0%)
build/product-rating-frontend.js 1.59 kB +114 B (+8%) 🔍
build/product-rating.js 919 B +105 B (+13%) ⚠️
build/product-search.js 2.61 kB -2 B (0%)
build/product-tag.js 8.06 kB -1 B (0%)
build/product-title.js 3.31 kB -2 B (0%)
build/products-by-attribute.js 8.5 kB -1 B (0%)
build/rating-filter.js 7.38 kB +3 B (0%)
build/reviews-by-category.js 11.2 kB -2 B (0%)
build/single-product.js 9.97 kB -1 B (0%)
build/stock-filter.js 8.12 kB +4 B (0%)
build/wc-blocks-editor-style-rtl.css 5.26 kB +13 B (0%)
build/wc-blocks-editor-style.css 5.27 kB +12 B (0%)
build/wc-blocks-style-rtl.css 24.8 kB +106 B (0%)
build/wc-blocks-style.css 24.8 kB +106 B (0%)
build/wc-blocks-vendors.js 62.7 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.74 kB
build/active-filters-wrapper-frontend.js 6.01 kB
build/all-products-frontend.js 11.3 kB
build/attribute-filter-frontend.js 22.7 kB
build/attribute-filter-wrapper-frontend.js 7.67 kB
build/attribute-filter.js 12.3 kB
build/blocks-checkout.js 39.5 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.37 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.08 kB
build/cart-blocks/cart-express-payment-frontend.js 720 B
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.29 kB
build/cart-blocks/cart-line-items-frontend.js 1.07 kB
build/cart-blocks/cart-order-summary-frontend.js 1.25 kB
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/empty-cart-frontend.js 343 B
build/cart-blocks/filled-cart-frontend.js 783 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.78 kB
build/cart-blocks/order-summary-discount-frontend.js 2.13 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 455 B
build/cart-blocks/order-summary-shipping-frontend.js 14.6 kB
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 436 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.24 kB
build/checkout-blocks/actions-frontend.js 1.86 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 3.86 kB
build/checkout-blocks/billing-address-frontend.js 1.12 kB
build/checkout-blocks/contact-information-frontend.js 2 kB
build/checkout-blocks/express-payment-frontend.js 1.14 kB
build/checkout-blocks/fields-frontend.js 343 B
build/checkout-blocks/order-note-frontend.js 1.14 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.93 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.25 kB
build/checkout-blocks/order-summary-shipping-frontend.js 14.6 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 436 B
build/checkout-blocks/payment-frontend.js 8.34 kB
build/checkout-blocks/shipping-address-frontend.js 1.11 kB
build/checkout-blocks/shipping-methods-frontend.js 4.57 kB
build/checkout-blocks/terms-frontend.js 1.56 kB
build/checkout-blocks/totals-frontend.js 324 B
build/checkout-frontend.js 29.4 kB
build/customer-account.js 3.08 kB
build/filter-wrapper-frontend.js 13.8 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/handpicked-products.js 7.21 kB
build/mini-cart-component-frontend.js 20 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/filled-cart-frontend.js 388 B
build/mini-cart-contents-block/footer-frontend.js 2.81 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 591 B
build/mini-cart-contents-block/shopping-button-frontend.js 313 B
build/mini-cart-contents-block/title-frontend.js 368 B
build/mini-cart-contents.js 16.6 kB
build/mini-cart-frontend.js 1.88 kB
build/price-filter-frontend.js 13.6 kB
build/price-filter-wrapper-frontend.js 7.01 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 225 B
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-add-to-cart-frontend.js 6.71 kB
build/product-add-to-cart.js 8.47 kB
build/product-best-sellers.js 7.58 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 441 B
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 302 B
build/product-button-frontend.js 2.15 kB
build/product-button.js 3.84 kB
build/product-categories.js 2.36 kB
build/product-category-list-frontend.js 1.14 kB
build/product-category-list.js 502 B
build/product-image-frontend.js 2.16 kB
build/product-new.js 7.58 kB
build/product-price-frontend.js 2.18 kB
build/product-price.js 1.54 kB
build/product-sale-badge-frontend.js 1.39 kB
build/product-sale-badge.js 815 B
build/product-sku-frontend.js 629 B
build/product-sku.js 377 B
build/product-stock-indicator-frontend.js 1.26 kB
build/product-stock-indicator.js 646 B
build/product-summary-frontend.js 1.53 kB
build/product-summary.js 919 B
build/product-tag-list-frontend.js 1.13 kB
build/product-tag-list.js 498 B
build/product-title-frontend.js 1.59 kB
build/product-top-rated.js 7.82 kB
build/rating-filter-frontend.js 21.2 kB
build/rating-filter-wrapper-frontend.js 6.19 kB
build/reviews-by-product.js 12.3 kB
build/reviews-frontend.js 6.88 kB
build/single-product-frontend.js 17.3 kB
build/stock-filter-frontend.js 20.8 kB
build/stock-filter-wrapper-frontend.js 5.85 kB
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--cde4eab5-frontend.js 6.86 kB
build/vendors--attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 7.7 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--671ca56f-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.53 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.82 kB
build/vendors--checkout-blocks/shipping-methods-frontend.js 9.48 kB
build/wc-blocks-data.js 21.1 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 931 B
build/wc-blocks-registry.js 2.92 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.72 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@nerrad
Copy link
Contributor

nerrad commented Dec 13, 2022

Thanks for doing this! I see in your screenshots that the price for some products is wrapped on inline with the ratings? Do you know if this is intentional? I think ratings and price should be stacked right?

@Aljullu
Copy link
Contributor

Aljullu commented Dec 13, 2022

I didn't review it yet, but I'm a bit concerned that the empty stars look like a 0 rating. IMO the Before behavior shown in the screenshots is a valid one and can be seen online in existing stores, so I do think we should support it.

Some thoughts:

  • Could this be made an option so stores can decide which behavior they prefer?
  • If the issue is about the layout breaking when some products have ratings and others don't. Could we explore adding a Minimum height to the Product rating block? That would preserve the layout in cases where some products have ratings and others don't. (Sidenote: if we go this way, I'm uncertain whether it's better to use the Minimum height global styles option or hard-coding it in CSS)
  • Another idea would be to have a different layout for 'no rating' stars. Ie, something like only the outline of the stars. Or simply displaying a 'No ratings' text.

@nerrad

@danieldudzic
Copy link
Contributor

I didn't review it yet, but I'm a bit concerned that the empty stars look like a 0 rating. IMO the Before behavior shown in the screenshots is a valid one and can be seen online in existing stores, so I do think we should support it.

Another idea would be to have a different layout for 'no rating' stars. Ie, something like only the outline of the stars. Or simply displaying a 'No ratings' text.

In my opinion, there should be an option to hide empty ratings, but I also second the idea to use a different design for no ratings - the outline sounds reasonable and doesn't clutter the layout with extraneous text.

@nerrad
Copy link
Contributor

nerrad commented Dec 13, 2022

I didn't review it yet, but I'm a bit concerned that the empty stars look like a 0 rating.

I didn't think of that but it makes sense.

Could this be made an option so stores can decide which behavior they prefer?

Karol asked me this in chat and I initially answered we should wait until we get feedback but if it's trivial to add the toggle I'm okay with doing so. I'm not sure we should go with an alternative design to represent "no ratings", I'm not sure how that's any more clearer than the current iteration. I imagine "outline" vs "fill" for ratings might be a design choice as well for the stars themselves eventually.

Sidenote: if we go this way, I'm uncertain whether it's better to use the Minimum height global styles option or hard-coding it in CSS

If adding an option to hide no ratings is more complex, happy to try this approach first and agree the minimum height global styles option is likely the best approach here (I'm not sure what the rendered CSS is offhand though and if there are additional complexities we need to consider about potential surrounding blocks in patterns etc).

@kmanijak
Copy link
Contributor Author

I see in your screenshots that the price for some products is wrapped on inline with the ratings? Do you know if this is intentional? I think ratings and price should be stacked right?

It happens for PHP template, and I assumed it's expected since that's how it works on trunk as well. But once you mentioned that, I'm pretty sure it's not expected. Let me create an issue. 👍


if it's trivial to add the toggle I'm okay with doing so

If adding an option to hide no ratings is more complex, happy to try this approach first and agree the minimum height global styles option is likely the best approach here

So in case of adding a toggle that would mean:

  • Add toggle to All Products settings: "Show empty ratings" with default value false
  • Add toggle to Product Ratings block settings (used in Products): "Show empty ratings" with default value false
  • To my understanding, PHP template is not configurable. In such a case shall we always show or always hide the no rating?

It's hard for me to assess if it's trivial or not. I can timebox the toggle work to 30-60minutes and in case it's becoming complex, I'll switch to min-height solution. How does it sound?

@nerrad
Copy link
Contributor

nerrad commented Dec 13, 2022

Add toggle to All Products settings: "Show empty ratings" with default value false
Add toggle to Product Ratings block settings (used in Products): "Show empty ratings" with default value false

Wouldn't it just be a control configured with the Product Ratings block (and thus available in both contexts)? The products rating block can be selected with the All Products block.

To my understanding, PHP template is not configurable. In such a case shall we always show or always hide the no rating?

If you're talking about the rendered classic template, correct - it's not configurable and we won't worry about the classic templates for now. As we blockify the templates the existing product element blocks will allow for finer control.

@kmanijak
Copy link
Contributor Author

Wouldn't it just be a control configured with the Product Ratings block (and thus available in both contexts)? The products rating block can be selected with the All Products block.

My bad, you're right!

But I'm thinking now: the main reason for the change was to preserve the layout. Making the empty rating configurable with the default to NOT show the empty rating, I'd definitely go with min-height approach.
In this case empty rating helps only those who enable that.
Min-height would provide generic solution for everyone.

@nefeline
Copy link
Contributor

nefeline commented Dec 13, 2022

Another idea would be to have a different layout for 'no rating' stars. Ie, something like only the outline of the stars. Or simply displaying a 'No ratings' text.

I like this idea too. Sharing my 1% here:

I've seen websites where there's text on the side of the star ratings indicating when a product has no reviews:

Screenshot 2022-12-13 at 19 08 24

When reviews are available, the label is then updated to:

Screenshot 2022-12-13 at 19 08 42

Maybe that's an option we can explore?

@kmanijak
Copy link
Contributor Author

@nefeline, I like the idea, but I'm worried that adding text next to the stars may make the UI too crowded, especially on product grids.


I went through couple of online shops and another interesting idea is to either display a star rating or "Add review" link which brings you to #reviews section . What do you think about that?

image

@nefeline
Copy link
Contributor

I like the idea, but I'm worried that adding text next to the stars may make the UI too crowded, especially on product grids.

That's a fair concern

I went through couple of online shops and another interesting idea is to either display a star rating or "Add review" link which brings you to #reviews section . What do you think about that?

My 2 cents: I like this approach, it seems to be very clean and intuitive info to whoever is accessing the store.

@Aljullu
Copy link
Contributor

Aljullu commented Dec 14, 2022

I went through couple of online shops and another interesting idea is to either display a star rating or "Add review" link which brings you to #reviews section . What do you think about that?

I like this approach as well and prefer it over the "empty stars". In an ideal scenario, it would be possible to customize the text, so stores could delete it if they want that space to be empty.

Something similar to the Read more text in the Product Summary block:

Product Summary Read more text screenshot

@nerrad
Copy link
Contributor

nerrad commented Dec 14, 2022

I went through couple of online shops and another interesting idea is to either display a star rating or "Add review" link which brings you to #reviews section . What do you think about that?

I like this approach too! Agree with Albert that future iterations could provide an option for customizing but for now, we could just have the default.

@kmanijak
Copy link
Contributor Author

Agree with Albert that future iterations could provide an option for customizing but for now, we could just have the default.

Great!

So to sum up. If product has no ratings, "Add rating" link appears instead of stars. For now the link text is NOT modifiable and redirects to #reviews section. Change applies to:

  • All Products
  • Products
  • Legacy PHP template

I'll go ahead and reflect the outcome of this discussion in the issue #7923 and will repurpose this PR.

Thanks all for a great discussion! 🙌

@kmanijak kmanijak marked this pull request as draft December 14, 2022 13:52
@kmanijak kmanijak changed the title Display 5 "empty" stars as a default if there's no product rating Display "Add review" link if there's no product rating Dec 14, 2022
@woocommercebot woocommercebot requested a review from a team December 15, 2022 16:21
@kmanijak
Copy link
Contributor Author

@nefeline , @danieldudzic , PR has been updated and is ready for a review 🙏

Copy link
Contributor

@danieldudzic danieldudzic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Products and All Products: Display "Add review" link when there's no product rating

Maybe I'm nitpicking here, but perhaps it would make sense to indicate in the changelog message that this PR is relevant to the Rating product element:

Rating: Display "Add review" link when there's no product rating.

Copy link
Contributor

@danieldudzic danieldudzic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is working well and adding the Add Review link correctly. Good job!

I have noticed:

  1. The Alignment block setting is currently broken for the Rating element. I have tracked it down to this commit: cfb920a

  2. The Add review link should probably inherit the custom color setting:

Edit_Page_“Products”_‹ratings—_WordPress

$rating_count = $product->get_rating_count();
$reviews_link = $product->get_permalink() . '#reviews';
$link_label = __( 'Add review', 'woo-gutenberg-products-block' );
$link_html = '<a class="wc-block-components-product-rating__link" href="' . $reviews_link . '">' . esc_attr( $link_label ) . '</a>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to escape the href here:

Suggested change
$link_html = '<a class="wc-block-components-product-rating__link" href="' . $reviews_link . '">' . esc_attr( $link_label ) . '</a>';
$link_html = '<a class="wc-block-components-product-rating__link" href="' . esc_url( $reviews_link ) . '">' . esc_attr( $link_label ) . '</a>';;

&__link {
display: inline-block;
width: 100%;
text-align: center;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking the Alignment block setting for the link.

Suggested change
text-align: center;

@kmanijak kmanijak added type: enhancement The issue is a request for an enhancement. block-type: product elements Issues related to Product Element blocks. labels Dec 16, 2022
Copy link
Contributor

@nefeline nefeline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm 👏 ! This is testing well: also noticed the same points that @danieldudzic already flagged here.

I've recommended a change regarding how the rating HTML is structured since it is already being modified on the filter_rating_html method.

return sprintf(
'<div class="wc-block-components-product-rating wc-block-grid__product-rating %1$s %2$s" style="%3$s">
%4$s
</div>',
esc_attr( $text_align_styles_and_classes['class'] ?? '' ),
esc_attr( $styles_and_classes['classes'] ),
esc_attr( $styles_and_classes['styles'] ?? '' ),
wc_get_rating_html( $product->get_average_rating() )
$content
Copy link
Contributor

@nefeline nefeline Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are already adding a filter to modify WooCommerce's default rating HTML here on this Class (see the filter_rating_html method on L78), my recommendation is to move and consolidate the updates done here on render to that method instead. E.g.:

	public function filter_rating_html( $html, $rating, $count ) {
		$product_permalink = get_permalink();
		if ( 0 < $rating || false === $product_permalink ) {
			/* translators: %s: rating */
			$label   = sprintf( __( 'Rated %s out of 5', 'woo-gutenberg-products-block' ), $rating );
			$content = '<div class="wc-block-components-product-rating__stars wc-block-grid__product-rating__stars" role="img" aria-label="' . esc_attr( $label ) . '">' . wc_get_star_rating_html( $rating, $count ) . '</div>';
		} else {
			$product_review_url = esc_url( $product_permalink . '#reviews' );
			$content            = '<a class="wc-block-components-product-rating__link" href="' . $product_review_url . '">' . __( 'Add review', 'woo-gutenberg-products-block' ) . '</a>';
		}

		return $content;
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: thank you for this, that was my first idea, but I realised I have no clue where to get the product_permalink from. I didn't know I can simply call get_permalink() and that will work in a context of a particular product, so... Today I Learnt, thank you! 🎉

But once I tried that I found a bad consequences. This filter influences not only Products block, but also Classic Template. I'm not sure why and where's the mechanism responsible for that, but when another anchor is put inside (which "Add review" is), the Rating and a Price are pushed out of the product anchor. That brings inconsistency. Check the image out:

  • on the left: product which is wrapped in anchor HTML tag. Everything has a green color, since that's how I configured links
  • on the right: "Add review" is a link and it's been pushed out of product anchor. Price is red, which is a color of regular text.

image

Given the above I think I would go back to the previous solution. What do you think?

Copy link
Contributor

@nefeline nefeline Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: thank you for this, that was my first idea, but I realised I have no clue where to get the product_permalink from. I didn't know I can simply call get_permalink() and that will work in a context of a particular product, so... Today I Learnt, thank you! 🎉

Anytime 🙌 !

This filter influences not only Products block, but also Classic Template.

Out of curiosity: why would we want to display the "add review" link only on blocks?

I'm not sure why and where's the mechanism responsible for that, but when another anchor is put inside (which "Add review" is), the Rating and a Price are pushed out of the product anchor. That brings inconsistency.

I'm probably missing a piece of information here: do you mind clarifying this a bit more? Isn't this a consequence of what is being discussed over here (stars (which aren't links) follow the text color, while "Add review" follow the link color.)? I've compared both implementations side by side (consolidating everything on filter_rating_html versus keeping the changes on render), and I do not see any differences in terms of the structure of the divs or HTML anchors.

Given the above I think I would go back to the previous solution. What do you think?

No strong preferences on my end, although filtering the rating_html and then modifying the filtered result right after, on the same class, looks a bit redundant/confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nefeline for response!

Out of curiosity: why would we want to display the "add review" link only on blocks?

It's not like we want the link only on blocks. Actually it's a good step to cover Classic Template as well, but there's no high demand for that.

I'm probably missing a piece of information here: do you mind clarifying this a bit more?

Sure thing! Apologies it wasn't clear enough.

On the screen below you can see the that when there are stars (green), they are rendered within the product anchor (red) and the same goes for price. Product anchor wraps the whole content:
Screen Shot 2022-12-22 at 18 21 58 PM

However, when "Add Review" link is rendered, the Product anchor gets closed (I think browser may sanitize that) to avoid nested anchors (which is forbidden). The consequence is that "Add Review" link (green) and price are already outside of Product anchor (red). That changes the clicking area for product and causes potential UI differences if a user changed the global styles. It cannot be easily fixed as Classic Template "delegates" single product rendering to WC Core.
Screen Shot 2022-12-22 at 18 21 31 PM

Having said that, I think we should skip the Classic Template. Let me know if you have some idea how to overcome this, because I have to agree with your words:

filtering the rating_html and then modifying the filtered result right after, on the same class, looks a bit redundant/confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nefeline for the effort you took to show me why the above case is an edge case. It only happens when both: Products block and Classic Template are used on the same page (which I did to make the testing easier and didn't understand it influences the result).

When Classic Template is used alone on the page it stays untouched. It's very unlikely a merchant would use both those components on the same page, hence I applied the change as per your recommendation.

Having said that I think PR is ready for a final check! 🙌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update here @kmanijak ! This looks good now that we have removed the redundancy of modifying an already-filtered result.

It only happens when both: Products block and Classic Template are used on the same page

Not at all related to this PR in particular since the filter is pre-existing on the ProductRating class, but to prevent this behavior altogether and keep the Product Rating block customizations isolated, we would have to stop relying on the 'woocommerce_product_get_rating_html' filter and work ourselves on a parallel implementation instead.

It's very unlikely a merchant would use both those components on the same page

Yes, I agree: and even if they do, it still renders great and works as expected, except, of course, the custom block styles might not be applied on the Classic Template for obvious reasons :)

@kmanijak
Copy link
Contributor Author

@danieldudzic and @nefeline , I appreciate the reviews! 🙏

Review

The Alignment block setting is currently broken for the Rating element. I have tracked it down to this commit: cfb920a

You're right, I fixed that in this PR

The Add review link should probably inherit the custom color setting:

It does, but for links, which it is... But that brings inconsistency: stars (which aren't links) follow the text color, while "Add review" follow the link color.

image

To be honest, not sure what's better: semantic consistency (as it is right now) or blocks consistency. Do you have any opinion?

Remaining work

There's still one remaining thing I need to address: I added a placeholder while the Rating is loading. However that influences the Filter by Rating block (by accident it has is-loading class all the time).

… block

That could be done globally, however there's a bug that makes Filter by Rating keeping is-loading class which keeps the placeholder visible there all the time
@kmanijak
Copy link
Contributor Author

@nefeline , @danieldudzic

I updated the PR with the fix for loading placeholder issue which was introducing regression in Filter by Rating. In short: there's always is-loading class attached in the Filter by Rating. I wanted to fix that, however there's couple of edge cases that would have to be covered, hence I decided to create an issue for that. For it's just fixed by limiting the set of classes to which placeholder is applied (code).

I added few regression testing steps to the PR description, for Product view, Rating alignment and Filter by Rating.

Also, I responded to some of your comments with my concerns, I'm happy to hear your opinion about them. Other comments, with 👍 reaction are addressed.

I'd be grateful for another round of review here 🙏

@github-actions
Copy link
Contributor

github-actions bot commented Dec 27, 2022

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7929.zip

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 422
  • Total errors: 2023

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

Copy link
Contributor

@nefeline nefeline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've confirmed everything works as expected. Great work! 🚀

@github-actions github-actions bot added this to the 9.3.0 milestone Dec 27, 2022
@kmanijak
Copy link
Contributor Author

Merging with the bypass - E2E tests with Gutenberg fail, the same as on trunk. All the other checks are passing, including E2E without Gutenberg.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product elements Issues related to Product Element blocks. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display "Add review" link if there's no product rating
5 participants