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

Add 'Order notes' to Checkout block #2877

Merged
merged 14 commits into from Jul 31, 2020
Merged

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Jul 16, 2020

Fixes #1483.

Screenshots

imatge

How to test the changes in this Pull Request:

  1. Go to the Checkout block and check the 'Add a note to your order' checkbox.
  2. Introduce some text in the text area that appeared.
  3. Place the order and go to the admin, WooCommerce > Orders and verify the order has the note under Customer provided note.

Changelog

The Checkout block allows customers to introduce an order note. This feature can be disabled in the editor.

@Aljullu Aljullu added status: needs review type: enhancement The issue is a request for an enhancement. block: checkout Issues related to the checkout block. labels Jul 16, 2020
@Aljullu Aljullu added this to the 3.0.0 milestone Jul 16, 2020
@Aljullu Aljullu self-assigned this Jul 16, 2020
@@ -26,6 +26,7 @@ export const DEFAULT_STATE = {
hasError: false,
calculatingCount: 0,
orderId: checkoutData.order_id,
orderNotes: '',
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 the orderNotes value in the Checkout context. It doesn't belong to the Shipping data neither the Billing data, so adding it to those contexts felt wrong. At the same time, creating a specific context to only hold the order notes seemed a bit overwhelming. That's why I decided to use the Checkout context to store it, but I'm not 100% sure about it either.

Copy link
Member

Choose a reason for hiding this comment

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

This is consistent with the approach I took for createAccount - makes sense to me.

#2851 (comment)

Copy link
Contributor

@nerrad nerrad Jul 29, 2020

Choose a reason for hiding this comment

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

I think adding this to the checkout-state context was a good call here. One thing to remember is that checkout-state is a child of the Cart context provider too.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 16, 2020

Size Change: +2.21 kB (0%)

Total Size: 1.65 MB

Filename Size Change
build/all-products-frontend.js 30.9 kB +3 B (0%)
build/all-products.js 35.3 kB -1 B
build/all-reviews.js 9.67 kB -12 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 8.73 kB -3 B (0%)
build/atomic-block-components/add-to-cart.js 7.32 kB +1 B
build/atomic-block-components/button-frontend.js 1.99 kB -1 B
build/atomic-block-components/category-list-frontend.js 469 B +1 B
build/atomic-block-components/image.js 1.15 kB -1 B
build/atomic-block-components/summary-frontend.js 919 B +1 B
build/atomic-block-components/title-frontend.js 1.22 kB +1 B
build/attribute-filter-frontend.js 17.8 kB +1 B
build/attribute-filter.js 12.3 kB +1 B
build/cart-frontend.js 65.9 kB +75 B (0%)
build/cart.js 34.4 kB +58 B (0%)
build/checkout-frontend.js 83 kB +554 B (0%)
build/checkout.js 39.8 kB +563 B (1%)
build/handpicked-products.js 7.29 kB -1 B
build/product-best-sellers.js 7.36 kB -1 B
build/product-categories.js 3.23 kB -1 B
build/product-new.js 7.53 kB +2 B (0%)
build/product-on-sale.js 7.92 kB -1 B
build/product-top-rated.js 7.5 kB +1 B
build/reviews-by-category.js 11.7 kB +1 B
build/reviews-by-product.js 13.3 kB +1 B
build/single-product-frontend.js 33.7 kB +4 B (0%)
build/style-legacy-rtl.css 16.8 kB +241 B (1%)
build/style-legacy.css 16.8 kB +243 B (1%)
build/style-rtl.css 17.5 kB +241 B (1%)
build/style.css 17.5 kB +244 B (1%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.49 kB 0 B
build/active-filters.js 8.77 kB 0 B
build/all-reviews-legacy.js 9.34 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/button.js 3.12 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/image~atomic-block-components/title.js 334 B 0 B
build/atomic-block-components/button.js 839 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/image-frontend.js 1.7 kB 0 B
build/atomic-block-components/price-frontend.js 2.08 kB 0 B
build/atomic-block-components/price.js 2.11 kB 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/rating.js 527 B 0 B
build/atomic-block-components/sale-badge-frontend.js 862 B 0 B
build/atomic-block-components/sale-badge.js 864 B 0 B
build/atomic-block-components/sku-frontend.js 388 B 0 B
build/atomic-block-components/sku.js 394 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 571 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 464 B 0 B
build/atomic-block-components/tag-list.js 473 B 0 B
build/atomic-block-components/title.js 1.05 kB 0 B
build/blocks-legacy.js 3.54 kB 0 B
build/blocks.js 3.54 kB 0 B
build/editor-legacy-rtl.css 13.8 kB 0 B
build/editor-legacy.css 13.8 kB 0 B
build/editor-rtl.css 14 kB 0 B
build/editor.css 14 kB 0 B
build/featured-category-legacy.js 7.28 kB 0 B
build/featured-category.js 7.65 kB 0 B
build/featured-product-legacy.js 9.53 kB 0 B
build/featured-product.js 9.89 kB 0 B
build/handpicked-products-legacy.js 6.93 kB 0 B
build/price-filter-frontend.js 14.2 kB 0 B
build/price-filter.js 10.2 kB 0 B
build/product-best-sellers-legacy.js 7.01 kB 0 B
build/product-categories-legacy.js 3.23 kB 0 B
build/product-category-legacy.js 7.92 kB 0 B
build/product-category.js 8.3 kB 0 B
build/product-new-legacy.js 7.17 kB 0 B
build/product-on-sale-legacy.js 7.55 kB 0 B
build/product-search-legacy.js 3.15 kB 0 B
build/product-search.js 3.48 kB 0 B
build/product-tag-legacy.js 6.1 kB 0 B
build/product-tag.js 6.45 kB 0 B
build/product-top-rated-legacy.js 7.14 kB 0 B
build/products-by-attribute-legacy.js 7.91 kB 0 B
build/products-by-attribute.js 8.24 kB 0 B
build/reviews-by-category-legacy.js 11.3 kB 0 B
build/reviews-by-product-legacy.js 12.8 kB 0 B
build/reviews-frontend-legacy.js 8.22 kB 0 B
build/reviews-frontend.js 9.08 kB 0 B
build/single-product.js 10 kB 0 B
build/vendors-legacy.js 367 kB 0 B
build/vendors-style-legacy-rtl.css 1.03 kB 0 B
build/vendors-style-legacy.css 1.03 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors.js 416 kB 0 B
build/vendors~atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.09 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.28 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 796 B 0 B
build/wc-payment-method-cod.js 875 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 11.9 kB 0 B
build/wc-settings.js 2.14 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

@Aljullu Aljullu requested review from a team and senadir and removed request for a team July 16, 2020 13:47
@nerrad nerrad modified the milestones: 3.0.0, 3.1.0 Jul 20, 2020
Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

This is looking good and testing well. I tested with Chrome, Firefox, and Safari on macOS and Safari on iOS and saw no issues.

I've left some code polish comments - no blockers IMO, up to you if you think there's anything to address there.

UX wise I have a couple of thoughts, none are particularly critical - again, up to you if you want to follow up or merge as is.

  1. The note text is lost when if the shopper unticks the box. It would be nice if the text they enter is preserved when check/uncheck the box. Also, the text is lost if you navigate away - would be cool if this persisted somewhere, similar to how your address info is (sometimes) persisted.
  2. Grouping / naming of the editor option. This is pretty minor, and definitely shippable as is. Just wanting to raise it to avoid having more single-item option groups appear in the editor sidebar over time.

assets/js/base/components/textarea/index.js Outdated Show resolved Hide resolved
) => {
let newState;
let newState = state;
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the changes in 66f3d33, for example, it's not always sure we will assign a value to newState, so it's good to initialize it to the previous state to avoid unexpected errors.

@@ -35,22 +35,34 @@ const FormStep = ( {
description,
children,
disabled = false,
showCounter = false,
Copy link
Member

Choose a reason for hiding this comment

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

Is this a new prop for showing the step number? Seems handy. Should we add storybook or tests to verify this and clarify the interface?

A tweak to the name might be clearer IMO - e.g. showStepNumber or showStepIndex. Also I think the default should be true – I'm guessing that "hide" is the less common use.

Copy link
Member

Choose a reason for hiding this comment

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

Could also export two variations, NumberedFormStep or FormStep.

I wonder what happens when there are hidden-numbered steps in between numbered steps - would that mean we need control of the numbering? (Thinking ahead, not essential to consider now!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A tweak to the name might be clearer IMO - e.g. showStepNumber or showStepIndex. Also I think the default should be true – I'm guessing that "hide" is the less common use.

Makes a lot of sense, done in 9c3a480 and 0c8cf24.

I wonder what happens when there are hidden-numbered steps in between numbered steps - would that mean we need control of the numbering? (Thinking ahead, not essential to consider now!)

The counter is only incremented in steps that show the step number. I think this is good enough for now.

Copy link
Member

Choose a reason for hiding this comment

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

The counter is only incremented in steps that show the step number.

Awesome!

'woo-gutenberg-products-block'
)
: __(
'Notes about your order.',
Copy link
Member

Choose a reason for hiding this comment

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

Is this smart message implemented in the previous / legacy checkout? If this is new behaviour, might be safer to keep it super simple for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not implemented in the shortcode checkout, but I considered it didn't make much sense keeping the 'Notes about your order, e.g. special notes for delivery.' for orders which don't include shipping. I don't mind bringing it back, though.


@LevinMedia Checkout shortcode uses the string 'Notes about your order, e.g. special notes for delivery.' for the order notes placeholder. Does it make sense removing or changing the 'e.g. special notes for delivery' part for orders without shipping (digital products, for example)?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a nice new feature :)

@@ -2,9 +2,8 @@
top: -96px;
}

.wc-block-checkout__add-note,
.wc-block-checkout__keep-updated {
Copy link
Member

Choose a reason for hiding this comment

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

Assuming these are remnants from previous markup, no longer used :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. .wc-block-checkout__keep-updated is not used anywhere and .wc-block-checkout__add-note styles have been moved to its own file.

@@ -148,6 +149,28 @@ const BlockSettings = ( { attributes, setAttributes } ) => {
/>
) }
</PanelBody>
<PanelBody
title={ __( 'Order notes', 'woo-gutenberg-products-block' ) }
Copy link
Member

Choose a reason for hiding this comment

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

I see this is in a category of its own - not ideal. Keen for feedback from @LevinMedia about how to best group these options.

Maybe we could generalise the Address options group to Form options and include notes there.

Or maybe there are more options that might be grouped with order notes in future, so we could generalise the title/description.

Screen Shot 2020-07-27 at 12 55 47 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this is in a category of its own - not ideal.

Why is it not ideal? What would be ideal (I think you're suggesting generalizing the options as being the ideal?).

Form options might be a good call here given that future iterations might be adding more toggles (required postal codes for instance).

Copy link
Member

Choose a reason for hiding this comment

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

Just that groups of one wouldn't scale well and could become overwhelming. If there are more Order notes options coming in future then the group makes sense. Not a major :)

Comment on lines 188 to 195
case SET_ORDER_NOTES:
newState = {
...state,
orderNotes,
};
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does a new state need to be created every time SET_ORDER_NOTES is called? Could you compare orderNotes and only update the state if there's a change?

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 a check to ensure the new state is only created if order notes have changed: 66f3d33.

@@ -148,6 +149,28 @@ const BlockSettings = ( { attributes, setAttributes } ) => {
/>
) }
</PanelBody>
<PanelBody
title={ __( 'Order notes', 'woo-gutenberg-products-block' ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this is in a category of its own - not ideal.

Why is it not ideal? What would be ideal (I think you're suggesting generalizing the options as being the ideal?).

Form options might be a good call here given that future iterations might be adding more toggles (required postal codes for instance).

@Aljullu Aljullu force-pushed the fix/1483-checkout-order-notes branch from 49b7113 to 4a98c42 Compare July 30, 2020 15:35
@Aljullu Aljullu requested a review from a team as a code owner July 30, 2020 15:35
@Aljullu
Copy link
Contributor Author

Aljullu commented Jul 30, 2020

Thanks for the reviews @haszari & @nerrad.

The note text is lost when if the shopper unticks the box. It would be nice if the text they enter is preserved when check/uncheck the box. Also, the text is lost if you navigate away - would be cool if this persisted somewhere, similar to how your address info is (sometimes) persisted.

Fixed in 668ae71. 👍

Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

The note text is lost when if the shopper unticks the box. It would be nice if the text they enter is preserved when check/uncheck the box. Also, the text is lost if you navigate away - would be cool if this persisted somewhere, similar to how your address info is (sometimes) persisted.

Fixed in 668ae71. 👍

Looking good, thanks for addressing all the minor feedback too :)

@@ -35,22 +35,36 @@ const FormStep = ( {
description,
children,
disabled = false,
showStepNumber = false,
Copy link
Member

@haszari haszari Jul 31, 2020

Choose a reason for hiding this comment

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

I see the default is still false - that seems the wrong way around to me, as most steps have the number, showStepNumber=true is the previous behaviour. Not a blocker, just checking your intention here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... I don't have a strong opinion on this. Changed in 7397426.

Thanks for the review.

@Aljullu Aljullu merged commit ed6516b into main Jul 31, 2020
@Aljullu Aljullu deleted the fix/1483-checkout-order-notes branch July 31, 2020 15:17
@senadir senadir mentioned this pull request Aug 19, 2020
20 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: checkout Issues related to the checkout block. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Order Notes Field and options in the Checkout
4 participants