BUGFIX: dont show disabled products in grid and carousels element - #123
Conversation
0ed9f24 to
147a026
Compare
|
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. |
97e22f9 to
194a7ca
Compare
194a7ca to
6e21963
Compare
b656cf1 to
c989d2e
Compare
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
c989d2e to
588c2ac
Compare
|
PR rebased and commits are squashed 🙂 |
| use Doctrine\ORM\EntityManagerInterface; | ||
| use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
|
|
||
| final readonly class ProductsProvider implements ProductsProviderInterface |
There was a problem hiding this comment.
Why this class is necessary and why not just add required methods to ProductRepository?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_productbundle config.
Both options require end-user to make changes to plugin installation, so I guess it can be considered a BC break.
There was a problem hiding this comment.
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 :)
| ->from($this->productClass, 'p') | ||
| ->innerJoin('p.channels', 'c') | ||
| ->where('p.code IN (:codes)') | ||
| ->andWhere('p.enabled = true') |
There was a problem hiding this comment.
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.
a6f4c1f to
16100ae
Compare
16100ae to
95c8bb5
Compare
7a0c588 to
acd120f
Compare
acd120f to
d157af6
Compare
94c8633 to
b6cd4aa
Compare
569a637 to
cd6255f
Compare
cd6255f to
60f2211
Compare
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.