Jump to content

How to override pictures


paul@gh

Recommended Posts

Hello !

We need to display a default "No Picture" image when a variant has no image on its own instead of displaying ALL the product images.

In order to achieve this we needed to change the behavior of the ImageRetriever class.

Replacing

return (0 === count($filteredImages)) ? $images : $filteredImages;

By

return (0 === count($filteredImages)) ? [
            $this->getNoPictureImage($language)
        ] : $filteredImages;

As we do not want to modify Core code base, we had to

  1. Extends the ImageRetriever class
  2. Override the ProductPresenterFactoryCode class in order to instantiate our ImageRetriever class instead of the core one.

It is working as intended for us.

Pros

No modification of the Core classes

Cons

A lot of overridden code.
Even if we extends the core classes (ProductPresenterFactoryCore and ImageRetriever),  we had to override every properties and methods as they are not intended to be extended (private property, ...).

In my opinion this is really bad. We should be able to alter core behavior without relying on so much code override.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...