Skip to content

Conversation

samueljseay
Copy link
Contributor

@samueljseay samueljseay commented May 29, 2025

Changes proposed in this Pull Request:

This PR introduces rendering of the mini cart items in the drawer via the interactivity API (behind experimental flag like in previous PRs).

Not all functionality is yet supported but increasing/decreasing quantities is supported via the UI steppers.

Also note that there is a flicker of items when changing quantities. I plan to address improvements to the store and this issue in a follow up PR. I will also support removing items entirely in a separate PR

Screenshots or screen recordings:

Screen.Recording.2025-06-02.at.2.26.51.PM.mov

How to test the changes in this Pull Request:

  1. Install the WooCommerce Beta Tester plugin
  2. From admin, go Tools > WCA Helper > Features (tab) > Enable the experimental-iapi-mini-cart toggle.
  3. Reload site on frontend, see the iAPI powered mini cart which has some functionality implemented.
  4. Add some items to your cart on the shop page
  5. Open drawer, see the items rendered
  6. Use the + and - steppers to increase/decrease quantities of the items (noting that removing/going to 0 is not implemented yet)

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

[Experimental] Render mini cart items using interactivity API when feature flag is enabled.

samueljseay and others added 30 commits May 13, 2025 19:12
…tils to format prices in MiniCartFooterBlock
@woocommerce woocommerce deleted a comment from github-actions bot Jun 2, 2025
Copy link
Contributor

github-actions bot commented Jun 2, 2025

Size Change: +384 B (+0.01%)

Total Size: 5.97 MB

Filename Size Change
./plugins/woocommerce/client/blocks/build/woocommerce/mini-cart.js 2.66 kB +384 B (+16.86%) ⚠️

compressed-size-action

Copy link
Contributor

github-actions bot commented Jun 2, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@samueljseay samueljseay requested a review from luisherranz June 3, 2025 09:58
Copy link
Contributor

github-actions bot commented Jun 3, 2025

Testing Guidelines

Hi @luisherranz ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

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

LGTM, Sam. This is looking great so far 🙂👏

Pre-approving with some comments.

Comment on lines +46 to +55
$reduce_quantity_label = __( 'Reduce quantity of %s', 'woocommerce' );

// translators: %s is the name of the product in cart.
$increase_quantity_label = __( 'Increase quantity of %s', 'woocommerce' );

// translators: %s is the name of the product in cart.
$quantity_description_label = __( 'Quantity of %s in your cart', 'woocommerce' );

// translators: %s is the name of the product in cart.
$remove_from_cart_label = __( 'Remove %s from cart', 'woocommerce' );
Copy link
Contributor

Choose a reason for hiding this comment

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

In the Product Button block, Luigi replaced %s with ###. I guess that's not necessary, right? We should probably change it there too, for consistency.

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 don't see why it would be necessary. I can ask him about it and do a follow up for consistency.

},

// Intended to be used in context of a cart item in wp-each
itemShortDescription() {
Copy link
Contributor

Choose a reason for hiding this comment

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

My take is that this should be moved to callbacks. I understand that it is due to the limitation of not yet having a directive for the HTML, but I'd move it anyway to keep only state and derived state inside state.

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 that makes sense 👍🏻

</div>
<div class="wc-block-components-product-metadata">
<div data-wp-watch="state.itemShortDescription" >
<div class="wc-block-components-product-metadata__description" data-wp-ignore></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, this is very interesting. I wonder why you need data-wp-ignore here. I was thinking about deprecating and the removing it, as we haven't found any use case for it (and it's a very complex and confusing directive).

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 I forgot to revisit this 🤦🏻‍♂️ . I assumed by the name of it that it was a way to tell interactivity API that I don't want it to control rendering this region, now looking at it I see it is sorta like that, but would likely only make sense to do it, if it has some initial inner content to cache? I think I can remove this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's okay to delete it and see if everything works as it should. If it doesn't work, we'll research why.

Base automatically changed from dev/refactor-price-utils to trunk June 5, 2025 11:42
@samueljseay
Copy link
Contributor Author

samueljseay commented Jun 5, 2025

@luisherranz Could you help me debug tomorrow, there seem to be some issues with reflecting state updates, I can't work out where it's going wrong.
I've incorporated the wp-key change needed for the each to work properly, but cart item quantities don't update using the steppers anymore with the new derived state for the item context, but I can't see why they shouldn't.

I'm wondering if server side directive handling is part of the issue?

@samueljseay
Copy link
Contributor Author

samueljseay commented Jun 6, 2025

@luisherranz just adding some more thoughts:

A revert to the way we were using context before works: 3ff8785

We should still figure out whats going on, but one thing I don't like about the changes you made is its quite hard to reason about. I come back to finding the "context" being set to woocommerce quite confusing (and how that becomes the context for items in the loop), but also that we add another layer more indirection for a derived getter for the woocommerce context's cart item. It feels like coming back to maintain it that finding the source of the context feels like detective work.

It results in less code, but overall a lot more confusing in my opinion.

Still would be great to pair and try figure out why the current pattern is not working properly for me.

EDIT: I kept going with a new branch for the follow on quantity limits work. This branch: https://github.com/woocommerce/woocommerce/compare/dev/redo-cart-set-qty?expand=1 removes the duplicated cartItems state, but still relies on getContext from within the derived getters and everything functions as expected. I just can't get your original code of getting state directly from woocommerce namespace in the directive to work for me.

Copy link
Contributor

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

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

After investigating with @samueljseay and @DAreRodz, we discovered that the problem is a bug in data-wp-each, and @DAreRodz will prepare a pull request in the Interactivity API to solve it.

There is still an issue in the lineItemTotal update, for which we have to find a workaround.

@samueljseay
Copy link
Contributor Author

samueljseay commented Jun 10, 2025

@luisherranz how do you feel about merging this so we can continue? I've continued to iterate in #58589 and also in https://github.com/woocommerce/woocommerce/compare/wooplug-4502-interactivity-api-powered-mini-cart-display-salediscount?expand=1

Copy link
Contributor

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

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

Yes, let's do that. Sorry for the request changes.

@samueljseay samueljseay merged commit 56361b1 into trunk Jun 11, 2025
39 checks passed
@samueljseay samueljseay deleted the dev/cart-drawer-items branch June 11, 2025 01:04
@github-actions github-actions bot added this to the 10.0.0 milestone Jun 11, 2025
shaybanshee pushed a commit that referenced this pull request Jun 13, 2025
…ecrease quantity (#58370)

Co-authored-by: Luis Herranz <luisherranz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants