Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of "empty cart" notices when using a shortcode cart and the checkout block #38738

Merged
merged 4 commits into from Jun 27, 2023

Conversation

mikejolley
Copy link
Member

@mikejolley mikejolley commented Jun 15, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

C&C Blocks introduced some new notice markup via some updated templates. These templates use a different HTML structure than the notices in core. The core notices get a special classname added in wc_empty_cart_message called cart-empty, but this is not added to the new Block notices because of the updated markup. For reference:

$notice  = str_replace( 'class="woocommerce-info"', 'class="cart-empty woocommerce-info"', $notice );

Cart.js uses the cart-empty to target elements from ajax responses. This is handled within update_wc_div. Because the cart-empty class does not exist when using blocks, this update fails and so after interacting with the shortcode cart, the page is emptied.

The fix in this PR is to wrap everything returned by wc_empty_cart_message with a new wc-empty-cart-message classname, which is then used by cart.js so the update works in both contexts.

Closes #38719

How to test the changes in this Pull Request:

This needs to be tested twice to ensure there are no regressions.

Test 1:
For the pages assigned as cart/checkout under WooCommerce > Settings > Advanced:

  • ensure that the Cart Page contains only the [woocommerce_cart] shortcode
  • ensure that the Checkout Page contains only the [woocommerce_checkout] shortcode
  1. Add an item to the cart
  2. View the cart page
  3. Remove all items from the cart using the X link
  4. The page should show the following:

Screenshot 2023-06-15 at 11 42 01

Test 2
For the pages assigned as cart/checkout under WooCommerce > Settings > Advanced:

  • ensure that the Cart Page contains only the [woocommerce_cart] shortcode
  • ensure that the Checkout Page contains only the Checkout Block
  1. Add an item to the cart
  2. View the cart page
  3. Remove all items from the cart using the X link
  4. The page should show the following:

Screenshot 2023-06-15 at 11 41 31

Notice the styling is updated between tests.

@mikejolley mikejolley added the package: @woocommerce/extend-cart-checkout-block Issues related to @woocommerce/extend-cart-checkout-block package label Jun 15, 2023
@mikejolley mikejolley self-assigned this Jun 15, 2023
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jun 15, 2023
@mikejolley mikejolley requested review from a team and nielslange and removed request for a team June 15, 2023 10:44
@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2023

Hi @jorgeatorres, @nielslange,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@mikejolley mikejolley requested review from a team and jorgeatorres and removed request for a team June 15, 2023 10:45
@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2023

Test Results Summary

Commit SHA: 6592168

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 54s
E2E Tests1900018020814m 44s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

Copy link
Member

@nielslange nielslange 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 working on this, @mikejolley.

While reviewing the PR, I wasn't able to see the 2nd screenshot that you mentioned.

Cart shortcode:

Screenshot 2023-06-19 at 08 16 03
Checkout shortcode:

Screenshot 2023-06-19 at 08 17 35
Cart block:

Screenshot 2023-06-19 at 08 18 42
Checkout block:

Screenshot 2023-06-19 at 08 19 59

Do you have any idea on why the design of your 2nd screenshot is not visible on my end?

Apart from the screenshot, I found the 2nd testing instructions ("Next, edit your CHECKOUT page ...") a bit confusing. While the title says to replace the checkout shortcode with the Checkout block, the instructions do not mention tests on the checkout page. To me, it was not clear whether I should check the checkout page or not.

@mikejolley
Copy link
Member Author

@nielslange you'll only see the new design if the checkout page assigned under WooCommerce > settings > advanced actually contains the checkout block, hence the instructions "Next, edit your CHECKOUT page and insert the checkout block in place of the shortcode."

@jorgeatorres
Copy link
Member

Hey @mikejolley!

There are a couple of PHPCS violations (see https://github.com/woocommerce/woocommerce/actions/runs/5277832291/jobs/9546360759?pr=38738) which need to be addressed before merging this. I can confirm that the PR does fix the "empty cart" notice situation (when the checkout page uses the checkout block).

Even if not directly related to this PR, I noticed a couple of things while testing, which maybe you can comment on:

  • With the cart page using the shortcode, and the checkout page using the checkout block, I no longer see the "Product removed. Undo?" notice:
    Untitled3
  • You can also see above that the empty cart notice is styled differently as compared to when the checkout page uses the shortcode:
    Screenshot 2023-06-20 at 10 17 00

FWIW, I'm testing with StoreFront.

@nielslange
Copy link
Member

@nielslange you'll only see the new design if the checkout page assigned under WooCommerce > settings > advanced actually contains the checkout block, hence the instructions "Next, edit your CHECKOUT page and insert the checkout block in place of the shortcode."

I did that, @mikejolley, but I'll double-check it. It appears that there's something wrong with my local environment the previous days. Somehow, I keep getting different results than others.

@nielslange
Copy link
Member

@mikejolley I tested it again, and I'm getting the same result. When using the Cart block, I do not see the notice.

Here are the steps I took:

  1. Check out your PR.
  2. Ran nvm use && pnpm i && pnpm build.
  3. Create a test page with the Cart block.
  4. Define that page as the Cart page via /wp-admin/admin.php?page=wc-settings&tab=advanced.
  5. Go to the frontend.
  6. Add a product to the cart.
  7. Go to the cart page.
  8. Remove the product from the cart.
  9. See the info Your cart is currently empty!.

This only happens when using the Cart block. When using the Cart shortcode, I do see the notices.

@mikejolley mikejolley changed the title Fix display of empty cart notices when using Cart and Checkout Blocks Fix display of "empty cart" notices when using a shortcode cart and the checkout block Jun 26, 2023
@nielslange nielslange self-requested a review June 26, 2023 10:54
Copy link
Member

@nielslange nielslange 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 working on this, @mikejolley.

I've tested this PR successfully with the following setup and result:

Test case 1 Test case 2
Page Setup » Cart page

[woocommerce_cart]

[woocommerce_cart]

Page Setup » Checkout page

[woocommerce_checkout]

📦 Checkout block
Screenshot » Cart page Screenshot 2023-06-26 at 13 00 10 Screenshot 2023-06-26 at 13 01 03

@mikejolley
Copy link
Member Author

Thanks @nielslange

@jorgeatorres I fixed those up. Notice styling is expected to differ due to blocks changing the notice markup and including its own styles.

Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

LGTM

@jorgeatorres jorgeatorres merged commit 84171ba into trunk Jun 27, 2023
18 checks passed
@jorgeatorres jorgeatorres deleted the fix/38719-empty-cart-notices-with-blocks branch June 27, 2023 19:35
@github-actions github-actions bot added this to the 8.0.0 milestone Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: @woocommerce/extend-cart-checkout-block Issues related to @woocommerce/extend-cart-checkout-block package plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shortcode cart: Undo functionality no longer visible
3 participants