Our requirement is a promotion slider on product canonicals that promotes similar products. We also have the stock module installed, and show a little banner that says "currently out of stock" to any product on the main page. The Problem is, that in this promo slider no out of stock products shall be promoted.

My approach

A filter in the slider view, that filters out all the products that have all there variations out of stock. That only leaves behind all the products that have at least one variation in stock. But the variations are still getting injected into the product view, because that is not part of the view logic. The "Add to cart" button and select widget have a filter event ProductEvents::FILTER_VARIATIONS which could be used to filter out all the out of stock products. But than it would be in all of my teasers and not only in the once of the slider, because in the event I don't get the view mode passed along (missing context in general). Also this event is triggered only in ProductVariationStorage::loadEnabled(), although there are at least 2 more ways to retrieve the variations. Now I seem to be only with one very ugly and prone to bugs solution left, to override all the injected variation_ fields in a preprocess function.


Is that the way to go, or is there a better one? Why are there so many different ways of fetching the variations? Can we streamline that a bit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.