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

Show total sale badge in medium carts & make it display below price #3879

Merged
merged 7 commits into from
Feb 23, 2021

Conversation

opr
Copy link
Contributor

@opr opr commented Feb 22, 2021

When the price and sale badge are short, they appear on the same line. During testing, the product sale badge was usually long enough to cause it to break onto a new line so this went unnoticed.

By setting the class .wc-block-components-product-price to be block it ensures the badge will always display below the price.

I also noticed that the sale badge didn't display when the block size was medium, so I have allowed it to display there. This was especially noticeable in the TwentyTwenty theme when the block size is always medium.

Screenshots

Before

image

After

image

How to test the changes in this Pull Request:

  1. Set your currency settings to display without a decimal place, like this: image
  2. Add a product that is on sale to your cart, if you've got an up to date WooCommerce Subscriptions repo (on branch: feature/checkout-block-simple-multiple-subscriptions) then add a subscription product that's on sale, too.
  3. View the Cart block and ensure the price and sale badge display well.

Changelog

Ensure the sale badge is displayed well when a product price is short in the Cart block.

@opr opr added type: bug The issue/PR concerns a confirmed bug. focus: blocks Specific work involving or impacting how blocks behave. block: cart Issues related to the cart block. labels Feb 22, 2021
@opr opr added this to the 4.5.2 milestone Feb 22, 2021
@opr opr self-assigned this Feb 22, 2021
@opr opr requested a review from a team as a code owner February 22, 2021 15:18
@opr opr requested review from Aljullu and removed request for a team February 22, 2021 15:18
@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2021

Size Change: +97 B (0%)

Total Size: 1.15 MB

Filename Size Change
build/cart-frontend.js 75.7 kB +27 B (0%)
build/cart.js 38.5 kB +18 B (0%)
build/style-rtl.css 18.9 kB +26 B (0%)
build/style.css 18.9 kB +26 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.35 kB 0 B
build/active-filters.js 8.52 kB 0 B
build/all-products-frontend.js 34.8 kB 0 B
build/all-products.js 36.4 kB 0 B
build/all-reviews.js 9.89 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.37 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/add-to-cart-frontend.js 9.23 kB 0 B
build/atomic-block-components/add-to-cart.js 7.69 kB 0 B
build/atomic-block-components/button-frontend.js 2.39 kB 0 B
build/atomic-block-components/button.js 840 B 0 B
build/atomic-block-components/category-list-frontend.js 470 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/image-frontend.js 1.77 kB 0 B
build/atomic-block-components/image.js 1.23 kB 0 B
build/atomic-block-components/price-frontend.js 1.94 kB 0 B
build/atomic-block-components/price.js 1.96 kB 0 B
build/atomic-block-components/rating-frontend.js 520 B 0 B
build/atomic-block-components/rating.js 526 B 0 B
build/atomic-block-components/sale-badge-frontend.js 857 B 0 B
build/atomic-block-components/sale-badge.js 866 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/sku.js 393 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 569 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary-frontend.js 920 B 0 B
build/atomic-block-components/summary.js 925 B 0 B
build/atomic-block-components/tag-list-frontend.js 465 B 0 B
build/atomic-block-components/tag-list.js 473 B 0 B
build/atomic-block-components/title-frontend.js 1.35 kB 0 B
build/atomic-block-components/title.js 1.21 kB 0 B
build/attribute-filter-frontend.js 18.3 kB 0 B
build/attribute-filter.js 12.5 kB 0 B
build/blocks-checkout.js 17 kB 0 B
build/blocks.js 3.49 kB 0 B
build/checkout-frontend.js 80.4 kB 0 B
build/checkout.js 41.3 kB 0 B
build/editor-rtl.css 14.9 kB 0 B
build/editor.css 14.9 kB 0 B
build/featured-category.js 7.83 kB 0 B
build/featured-product.js 10.1 kB 0 B
build/handpicked-products.js 7.51 kB 0 B
build/price-filter-frontend.js 14.6 kB 0 B
build/price-filter.js 9.95 kB 0 B
build/price-format.js 1.34 kB 0 B
build/product-best-sellers.js 7.58 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-category.js 8.52 kB 0 B
build/product-new.js 7.75 kB 0 B
build/product-on-sale.js 8.14 kB 0 B
build/product-search.js 3.58 kB 0 B
build/product-tag.js 6.58 kB 0 B
build/product-top-rated.js 7.72 kB 0 B
build/products-by-attribute.js 8.5 kB 0 B
build/reviews-by-category.js 12 kB 0 B
build/reviews-by-product.js 13.5 kB 0 B
build/reviews-frontend.js 9.52 kB 0 B
build/single-product-frontend.js 37.9 kB 0 B
build/single-product.js 10.3 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 6.53 kB 0 B
build/vendors-style-rtl.css 1.05 kB 0 B
build/vendors-style.css 1.05 kB 0 B
build/vendors.js 418 kB 0 B
build/wc-blocks-data.js 6.97 kB 0 B
build/wc-blocks-middleware.js 1.1 kB 0 B
build/wc-blocks-registry.js 2.67 kB 0 B
build/wc-payment-method-bacs.js 820 B 0 B
build/wc-payment-method-cheque.js 816 B 0 B
build/wc-payment-method-cod.js 913 B 0 B
build/wc-payment-method-paypal.js 853 B 0 B
build/wc-payment-method-stripe.js 12.2 kB 0 B
build/wc-settings.js 2.4 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.69 kB 0 B

compressed-size-action

@ralucaStan
Copy link
Contributor

This solution works but I see that ProductPrice has this class and there might be cases where it's needed to be inline.

What we could do is style locally, depending on the need.

So I am thinking of wrapping the price and disscount in a div and setting that as a flex container, with a column direction (style is inline for demo purpose only):

<td class="wc-block-cart-item__total">
  <div style="
      display: flex;
      flex-direction: column;
      align-items: flex-end;
  ">
    <span class="price wc-block-components-product-price">...</span>
    <div class="wc-block-components-product-badge wc-block-components-sale-badge">...</div>
  </div>
</td>

This way the elements will display correctly here.
What do you think? @opr

@ralucaStan ralucaStan self-requested a review February 22, 2021 16:18
Copy link
Contributor

@ralucaStan ralucaStan left a comment

Choose a reason for hiding this comment

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

Let me know what you think of the proposal to handle the display locally.

assets/js/blocks/cart-checkout/cart/full-cart/style.scss Outdated Show resolved Hide resolved
@opr
Copy link
Contributor Author

opr commented Feb 22, 2021

Thanks for the review @ralucaStan I've made the change you suggested, I would like to hear your thoughts on my choice of class name, wc-block-cart-item__total-price-and-sale-badge doesn't feel that great to me, but if you think it works then fine. Any other suggestions for this class name are welcome though.

@opr opr requested a review from ralucaStan February 22, 2021 17:38
@ralucaStan
Copy link
Contributor

@opr how about wc-block-cart-item__total-price-container or wc-block-cart-item__total-price-and-sale-wrapper

@opr opr merged commit 6401e17 into trunk Feb 23, 2021
@opr opr deleted the fix/price-sale-badge-display branch February 23, 2021 10:12
opr added a commit that referenced this pull request Feb 23, 2021
…3879)

* Show total sale badge in medium carts

* Add markup to cart line item row to enable it to be displayed as flex

* Add styling to display price and sale badge as flex

* Revert product price being displayed as block

* Rename sale badge and price wrapper

* Hide line-total sale badge on mobile

* Change class name on total price and sale badge wrapper again
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. focus: blocks Specific work involving or impacting how blocks behave. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants