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

Add subtotal to cart and checkout and update the CartLineItem component with new styles #3734

Merged
merged 20 commits into from Jan 27, 2021

Conversation

opr
Copy link
Contributor

@opr opr commented Jan 26, 2021

As per the designs in this figma file: eaQcoMs7E8Ys0YgxfkOKxR-fi-0%3A1 this PR:

  • Moves the quantity picker to below the product metadata in the cart block
  • Removes the trash icon on mobile in the cart block and lets the "remove item" text be visible on mobile
  • Adds a sale badge under the item total when the quantity is more than one and the item is on sale.
  • Removes the link to the product on the checkout sidebar.
  • Shows the individual item price below the product name in the checkout sidebar.
  • Moves the "total" of each product (individual total * quantity) to its own "column" on the sidebar.

I have added some design changes here because adding the subtotal below the item name without making the other design changes caused this to look very messy.

Fixes #3629
Fixes #3631

Accessibility

Screenshots

Cart

Before

Screenshot 2021-01-25 at 17 10 55

After

Screenshot 2021-01-25 at 17 09 58

Checkout

Before

Screenshot 2021-01-26 at 11 16 40

After

Screenshot 2021-01-26 at 11 45 58

How to test the changes in this Pull Request:

  1. Add items to your cart, some with sale prices, add multiple items etc.
  2. See that the subtotal for each item is shown below the item's name, and the overall total is shown to the right. (Overall total is item price * quantity).
  3. Try different themes out to see how the new design works there.

Changelog

Design tweaks to the cart page which move the quantity picker below each cart item and improve usability on mobile.

This is because we need to display the subtotal of the item AND the total (subtotal * quantity)
As per the new designs, the quantity picker should be moved below the product metadata, and the product subtotals should appear below the product name.
This is because the quantity picker is now displayed below the product metadata and name.
@opr opr added focus: blocks Specific work involving or impacting how blocks behave. block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. labels Jan 26, 2021
@opr opr self-assigned this Jan 26, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2021

Size Change: -3.96 kB (0%)

Total Size: 1.18 MB

Filename Size Change
build/active-filters-frontend.js 8.32 kB -4 B (0%)
build/active-filters.js 8.49 kB +2 B (0%)
build/all-products-frontend.js 34.7 kB +3 B (0%)
build/all-products.js 36 kB +1 B (0%)
build/all-reviews.js 9.88 kB -1 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 9.2 kB -1 B (0%)
build/atomic-block-components/add-to-cart.js 7.7 kB -1 B (0%)
build/atomic-block-components/button.js 838 B +1 B (0%)
build/atomic-block-components/image.js 1.13 kB -2 B (0%)
build/atomic-block-components/price.js 1.85 kB +4 B (0%)
build/atomic-block-components/rating.js 525 B +1 B (0%)
build/atomic-block-components/sale-badge.js 860 B -2 B (0%)
build/atomic-block-components/sku.js 393 B -1 B (0%)
build/atomic-block-components/stock-indicator.js 572 B -1 B (0%)
build/atomic-block-components/tag-list.js 472 B +1 B (0%)
build/atomic-block-components/title-frontend.js 1.35 kB +3 B (0%)
build/attribute-filter-frontend.js 18.2 kB +2 B (0%)
build/attribute-filter.js 12.5 kB +1 B (0%)
build/blocks.js 3.49 kB -3 B (0%)
build/cart-frontend.js 63.5 kB -147 B (0%)
build/cart.js 34.2 kB -25 B (0%)
build/checkout-frontend.js 89.3 kB +9 B (0%)
build/checkout.js 39.9 kB +57 B (0%)
build/featured-category.js 7.81 kB -3 B (0%)
build/featured-product.js 10 kB -2 B (0%)
build/handpicked-products.js 7.49 kB -3 B (0%)
build/price-filter-frontend.js 14.5 kB +2 B (0%)
build/price-filter.js 9.93 kB +3 B (0%)
build/product-best-sellers.js 7.57 kB +1 B (0%)
build/product-category.js 8.51 kB -2 B (0%)
build/product-new.js 7.74 kB -1 B (0%)
build/product-on-sale.js 8.12 kB +4 B (0%)
build/product-search.js 3.56 kB +1 B (0%)
build/product-tag.js 6.56 kB +1 B (0%)
build/product-top-rated.js 7.7 kB -2 B (0%)
build/products-by-attribute.js 8.49 kB +1 B (0%)
build/reviews-by-product.js 13.5 kB +6 B (0%)
build/reviews-frontend.js 9.51 kB +2 B (0%)
build/single-product.js 10.3 kB +4 B (0%)
build/style-rtl.css 18.6 kB -78 B (0%)
build/style.css 18.6 kB -81 B (0%)
build/vendors.js 431 kB -3.71 kB (-1%)
ℹ️ View Unchanged
Filename Size Change
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.34 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 336 B 0 B
build/atomic-block-components/button-frontend.js 2.35 kB 0 B
build/atomic-block-components/category-list-frontend.js 469 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/image-frontend.js 1.68 kB 0 B
build/atomic-block-components/price-frontend.js 1.83 kB 0 B
build/atomic-block-components/rating-frontend.js 521 B 0 B
build/atomic-block-components/sale-badge-frontend.js 859 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 569 B 0 B
build/atomic-block-components/summary-frontend.js 918 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/atomic-block-components/title.js 1.21 kB 0 B
build/blocks-checkout.js 50.1 kB 0 B
build/editor-rtl.css 14.9 kB 0 B
build/editor.css 14.9 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/reviews-by-category.js 11.9 kB 0 B
build/single-product-frontend.js 37.9 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 5.73 kB 0 B
build/vendors-style-rtl.css 1.05 kB 0 B
build/vendors-style.css 1.05 kB 0 B
build/wc-blocks-data.js 6.97 kB 0 B
build/wc-blocks-middleware.js 935 B 0 B
build/wc-blocks-registry.js 2.54 kB 0 B
build/wc-payment-method-bacs.js 775 B 0 B
build/wc-payment-method-cheque.js 771 B 0 B
build/wc-payment-method-cod.js 866 B 0 B
build/wc-payment-method-paypal.js 813 B 0 B
build/wc-payment-method-stripe.js 12.1 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.68 kB 0 B

compressed-size-action

@opr opr marked this pull request as ready for review January 26, 2021 11:46
@opr opr requested a review from a team as a code owner January 26, 2021 11:46
@opr opr requested review from Aljullu and removed request for a team January 26, 2021 11:46
@opr opr added this to the 4.4.0 milestone Jan 26, 2021
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Lots of improvements in this PR, good job @opr! I left some inline comments, I think they are quite minor but posting them here to know your thoughts.

const convertedLinePrice = Dinero( {
amount: parseInt( prices.raw_prices.price, 10 ),
precision: parseInt( prices.raw_prices.precision, 10 ),
} ).convertPrecision( currency.minorUnit );
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any dangers on using .convertPrecision() here and then using this value to calculate linePrice? I feel we should do all calculations first and only call .convertPrecision() when the value is going to be rendered, but not before it's used in further calculations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I have fixed this. Thanks 😸

quantity
) }
/>
<div className="wc-block-components-order-summary-item__product-details">
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this div needed for something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it to allow the "left column" (product image, name, subtotal, details) to be separated from the "right column" (the total price), but I see that it's actually not necessary, thanks for pointing it out.

@@ -69,7 +73,6 @@

.wc-block-components-order-summary-item__description {
padding-left: $gap-large;
padding-top: $gap;
padding-bottom: $gap;
line-height: 1.375;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should remove this line-height rule. Currently the product name and price are not vertically aligned because of it:
imatge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, looks nicer without 👍🏻

@@ -12,12 +12,13 @@

.wc-block-components-quantity-selector {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Quantity selector is closer to the product description than to the Remove item link.
imatge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To fix this I've removed the margin from the last-of-type of .wc-block-components-product-details and added margin to the bottom of .wc-block-components-product-metadata - do you think this was the right approach? I had to add 0.75em of margin because the Remove item text is quite small, so the gap looked bigger than the gap above.

@opr opr requested a review from Aljullu January 26, 2021 15:59
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @opr! I added one last question about the details margin, but LGTM.

@@ -3,6 +3,10 @@
list-style: none;
margin: 0.5em 0;
padding: 0;

&:last-of-type {
margin: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just curious, why removing also the top margin? Shouldn't this be margin-bottom: 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was just because the previous product-details element has a margin-bottom, and so the margin-top "overlaps" and doesn't actually do anything. I figured we could save a couple of bytes by doing it this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, but if there is only one product details list, then there is no margin-top, no? I think this is reproducible if you compare a variable subscription (has two details list) with a simple subscription (has one details list). The margin between the product description and the first details list will be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yea, you're correct. Thanks for pointing this out 🤦🏻‍♂️ fix pushed.

@Aljullu
Copy link
Contributor

Aljullu commented Jan 27, 2021

@opr one more thing that I completely forgot about! 🤦 We will need to update the skeleton markup. Currently when loading it shows the layout with the quantity selector in the middle column:

Peek.2021-01-27.10-33.mp4

The markup can be found here:

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/96ef975f8cdc0cf6af07eff2e0ae284b39aa0ec7/src/BlockTypes/Cart.php#L141

@opr opr requested a review from Aljullu January 27, 2021 10:45
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@opr opr merged commit e25e76f into trunk Jan 27, 2021
@opr opr deleted the add/subtotal-to-cart-and-checkout branch January 27, 2021 11:35
@mikejolley mikejolley added the type: enhancement The issue is a request for an enhancement. label Feb 1, 2021
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. block: checkout Issues related to the checkout block. focus: blocks Specific work involving or impacting how blocks behave. type: enhancement The issue is a request for an enhancement.
Projects
None yet
3 participants