Skip to content

BUGFIX: dont show disabled products in grid and carousels element - #123

Merged
TheMilek merged 6 commits into
Sylius:1.2from
crydotsnake:bugfix/dont-show-disabled-products-in-grid-and-carousels-element
Apr 30, 2026
Merged

BUGFIX: dont show disabled products in grid and carousels element#123
TheMilek merged 6 commits into
Sylius:1.2from
crydotsnake:bugfix/dont-show-disabled-products-in-grid-and-carousels-element

Conversation

@crydotsnake

@crydotsnake crydotsnake commented Nov 20, 2025

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? no
Related tickets fixes #119
License MIT

This PR makes sure that disabled products dont show in the product grid / carousels element.

If you click on a disabled product that is listed in the elements, it returns a exception.

@crydotsnake
crydotsnake requested a review from a team as a code owner November 20, 2025 16:27
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from 0ed9f24 to 147a026 Compare November 22, 2025 08:55
@crydotsnake

Copy link
Copy Markdown
Member Author

Since I had to implement the same filter logic for four content elements, I would suggest adding a general PHP class to retrieve the products using the filter logic and using it within the four content elements.

This way, we avoid duplicate code.

@TheMilek
TheMilek force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch 2 times, most recently from 97e22f9 to 194a7ca Compare January 20, 2026 13:38
@GSadee GSadee added the Bug Confirmed bugs or bugfixes. label Jan 20, 2026
Comment thread src/Provider/ProductsProvider.php Outdated
Comment thread src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php Outdated
@TheMilek
TheMilek force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from 194a7ca to 6e21963 Compare January 20, 2026 14:06
Comment thread src/Provider/ProductsProvider.php Outdated
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch 2 times, most recently from b656cf1 to c989d2e Compare April 17, 2026 20:18
@crydotsnake crydotsnake self-assigned this Apr 17, 2026
TASK: filter product list for enabled products and remove checks in twig templates

TASK: add enabled products filter logic also for products grid by taxon and products carousel by taxon element

TASK: introduce ProductsProvider class and extend filter logic

Add BC layer

TASK: get products via SQL query

TASK: run phpcs
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from c989d2e to 588c2ac Compare April 17, 2026 20:26
@crydotsnake

Copy link
Copy Markdown
Member Author

PR rebased and commits are squashed 🙂

@crydotsnake
crydotsnake requested a review from GSadee April 17, 2026 20:33
Comment thread src/Provider/ProductsProvider.php Outdated
Comment thread src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php Outdated
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;

final readonly class ProductsProvider implements ProductsProviderInterface

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this class is necessary and why not just add required methods to ProductRepository?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ProductRepository class isnt part of the CMSPlugin. So we would need to first add these methods in the sylius core where the class is. Or do i oversee something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sylius/resource allows to replace/extend repository from plugin as well as from App namespace, so there are two approaches:

  • Offer CmsProductTrait, which end-user should use in their custom App ProductRepository
  • Offer Cms ProductRepository extends Core ProductRepository uses CmsProductTrait, which end-user will configure in sylius_product bundle config.

Both options require end-user to make changes to plugin installation, so I guess it can be considered a BC break.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both options require end-user to make changes to plugin installation, so I guess it can be considered a BC break.

Then i would be more a fan of using the ProductProvider class. To avoid BC changes :)

Comment thread src/Provider/ProductsProvider.php Outdated
->from($this->productClass, 'p')
->innerJoin('p.channels', 'c')
->where('p.code IN (:codes)')
->andWhere('p.enabled = true')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Theoretically one more check is required: that product has at least one enabled variant.

productVariant::enabled is a relatively new property, better check how vanilla sylius handles it.

Comment thread src/Provider/ProductsProvider.php
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch 3 times, most recently from a6f4c1f to 16100ae Compare April 22, 2026 11:42
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from 16100ae to 95c8bb5 Compare April 22, 2026 11:49
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from 7a0c588 to acd120f Compare April 22, 2026 12:57
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from acd120f to d157af6 Compare April 22, 2026 13:07
@TheMilek
TheMilek changed the base branch from 1.1 to 1.2 April 22, 2026 13:43
@crydotsnake
crydotsnake requested a review from GSadee April 30, 2026 09:22
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch 4 times, most recently from 94c8633 to b6cd4aa Compare April 30, 2026 12:15
Comment thread UPGRADE-1.2.md Outdated
Comment thread UPGRADE-1.1.md Outdated
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch 3 times, most recently from 569a637 to cd6255f Compare April 30, 2026 12:26
@crydotsnake
crydotsnake force-pushed the bugfix/dont-show-disabled-products-in-grid-and-carousels-element branch from cd6255f to 60f2211 Compare April 30, 2026 12:27
@TheMilek
TheMilek merged commit 9571cd5 into Sylius:1.2 Apr 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Confirmed bugs or bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabled products still shown in CMS page grids/carousels

4 participants