Skip to content

Product Collection: carousel layout scaffolding and Editor experience #59519

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

Conversation

kmanijak
Copy link
Contributor

@kmanijak kmanijak commented Jul 8, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR includes:

  1. Experimental Carousel layout to Product Collection
  2. Block manipulation logic. When changing layout it does couple of things:
    • switching TO carousel:
      • replace Product Template block with Group block that includes the same Product Template and Product Gallery Next Prev Arrows*
      • removes Pagination block if exists
      • adjusts Inspector Controls by hiding Columns and Max Page to Show options and updating Products per Page label
      • notice about performance impact when setting over 30 products in Products in Carousel option
    • switching FROM carousel:
      • replace Group block with the same Product Template from inside and removes arrows
      • adds back Pagination if it's default collection (other collections don't include Pagination by default)
      • adjusts Inspector Controls
  • when
  1. Editor experience:
    • it took me a while to figure out the blocks composition: arrows vs product template but currently user is able to focus on specific blocks by clicking them which seems the most intuitive
    • Arrows can be positioned similarly to Product Gallery so they move on a 3x3 grid (top, center, bottom x left, center, ight, spread).
  2. Very limited frontend: for now frontend is very limited to just displaying products in scrollable container with simple snapping. There will be following PRs focusing on it, especially arrows are not displayed at all as they're not yet adjusted to this block.

Additional changes:

  • move plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/utils/get-inner-block-by-name.ts from Product Filters to plugins/woocommerce/client/blocks/assets/js/utils so I could reuse it as well
  • add mock to unit tests which starter to fail most likely due to module resolution change related to above.
  • that Arrows don't render on the frontend
  • that block's name is woocommerce/product-gallery-large-image-next-previous and this is kept as constant in Product Collection.

Closes #59402
Closes #59403

(For Bug Fixes) Bug introduced in PR # .

Screenshots or screen recordings:

carousel

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Install and activate the WooCommerce Beta Tester extension.
  2. Go to WooCommerce Admin Test Helper > Features and enable experimental-blocks

Default collection

  1. Create new post
  2. Add Product Collection and choose "create your own"
  3. Add some custom content and styling to Product Template
  4. Focus on Product Collection and choose Carousel layout
  5. Expected:
    • Layout has changed to single row of products
    • Product Template block was replaced with Group block including Next/Prev arrows and Product Template
    • Pagination block is removed
    • styling and inner content was preserved
  6. Try clicking through blocks inside:
    • Clicking on product element selects them
    • Clicking on arrows selects arrows (there is an issue with editor outlines, I'll tackle it separately)
  7. Save and go to frontend
  8. Expected:
    • Content and styling is preserved
    • Products can be scrolled horizontally and they snap to center
    • Arrows are not yet rendered (check description above)
    • Container is scrollable on mobile as well
  9. Go back to Editor
  10. Change layout back to Grid
  11. Expected:
    • Layout has changed to grid
    • Group block was replaced with Product Template
    • Pagination block is back
    • Arrows are removed
    • styling and inner content was preserved

Custom collection

Repeat previous steps for custom collection by choosing some collection, e.g. "On Sale" in step 2. The only difference is there's no Pagination block, hence:

  • it won't be removed in step 6
  • it won't be added in step 12.

Performance notice

Carousel is meant to display only single page hence we display performance notice when merchant decides to set too many products in carousel.

  1. Create new post
  2. Add Product Collection and choose any collection
  3. Focus on Product Collection and choose Carousel layout
  4. Expected: "Products per Page" changed to "Products in Carousel"
  5. Change the value to bigger than 30
  6. Expected: Notice is displayed and it's hidden when you get back below 30 products
image

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

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 8, 2025
@kmanijak kmanijak changed the title Wooplug 4883 product collection experimental carousel layout option and Product Collection: carousel layout Jul 8, 2025
@kmanijak kmanijak changed the title Product Collection: carousel layout Product Collection: carousel layout scaffolding and Editor experience Jul 12, 2025
@@ -34,6 +34,9 @@ jest.mock( '@woocommerce/settings', () => ( {
}
return defaultValue;
} ),
getSettingWithCoercion: jest.fn( ( key: string, defaultValue: unknown ) => {
return defaultValue;
} ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This tests has started to fail with getSettingWithCoercion is not a function. The test has been passing on trunk but failed on this branch which does not make much sense.

Here's what Claude told me:

The reason it works on trunk but fails on your branch is likely due to a difference in how the module resolution is working. On trunk, it might be falling back to the actual implementation for unmocked functions, while on your branch it's strictly enforcing the mock.

And I guess that may be it since I touched plugins/woocommerce/client/blocks/assets/js/utils* adding new util 🤷 Anyway, I added this mock and the test is passing.

@kmanijak
Copy link
Contributor Author

Thanks @gigitux for review!

I addressed your comments, including the one to move to supports.layout. For now, it's a hybrid:

  • existing layouts: grid and list are handled "manually" (as-is)
  • new layout: carousel is based on supports.layout attributes.

I refactored the code as well including:

  • extracting the functions you suggested and cleaning up the code a bit so it's more readable,
  • and made code more flexible, so for example previously it could leave arrows untouched if Product Template was no longer in a Group block. Now, they should be removed no matter what.

On top of it:

  • moved plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/utils/get-inner-block-by-name.ts from Product Filters to plugins/woocommerce/client/blocks/assets/js/utils so I could reuse it as well
  • added mock to unit tests which starter to fail most likely due to module resolution change related to above.

Can I ask you for re-review?

@kmanijak kmanijak requested a review from gigitux July 15, 2025 13:46
Copy link
Contributor

@gigitux gigitux 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 addressing the feedback and deciding to investigate and implement the carousel with supports.layout 🚀

I left feedback regarding the transition from the carousel layout. I am not convinced that we should remove blocks during the transition.

I'm pretty sure that you're aware, but we need to improve the layout of the warning:

Image

As above, it is not a blocker, we can fix it in a follow-up PR.

productTemplate?.clientId,
productTemplateUpdatedBlock
);
}
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 that we should add an extra logic to ensure that we carry all the blocks added in group block:

Screen.Capture.on.2025-07-17.at.09-58-40.mp4

Not a blocker; I'm fine if you want to refine it in a dedicated PR 👍

@kmanijak
Copy link
Contributor Author

Thanks for review @gigitux . I addressed the feedback:

  1. Here's improved warning notice
image
  1. I've updated the logic, so when switching from Carousel to other layout:
  • remove Arrows
  • move Product Template from Group to Product Collection or update it's attributes if it's not in Group
  • remove the Group if empty, leave otherwise (so custom content is preserved)
  • add Pagination if needed.

Let me know if you want to re-review or you're fine with it as-is 🙌

@gigitux
Copy link
Contributor

gigitux commented Jul 18, 2025

I can confirm that both issues have been fixed:

Screen.Capture.on.2025-07-18.at.19-33-20.mp4
image

Awesome! Let's merge it! 🚀

remove Arrows
move Product Template from Group to Product Collection or update it's attributes if it's not in Group
remove the Group if empty, leave otherwise (so custom content is preserved)
add Pagination if needed.

I didn't think about all these scenarios! It looks like that this is a good candidate for a unit test/integration test. I see two reasons:

  • Document the behaviors.
  • Ensure that we don't lose some cases with future refactors/improvements.

@kmanijak kmanijak merged commit c1b9b7d into trunk Jul 21, 2025
74 of 76 checks passed
@kmanijak kmanijak deleted the wooplug-4883-product-collection-experimental-carousel-layout-option-and branch July 21, 2025 06:58
@github-actions github-actions bot added this to the 10.1.0 milestone Jul 21, 2025
@kmanijak
Copy link
Contributor Author

I didn't think about all these scenarios! It looks like that this is a good candidate for a unit test/integration test. I see two reasons:
Document the behaviors.
Ensure that we don't lose some cases with future refactors/improvements.

Yeah., I'll be adding them 👍

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.

Product Collection: Carousel layout in Editor Product Collection: experimental Carousel layout option and scaffolding
2 participants