I have create a plugin to change image object and call image url directly from AWS S3 instead of magento.

Function should be call on any page where product image will be loaded.


<type name="Magento\Catalog\Block\Product\ImageBuilder">
      <plugin name="add_product_object_to_image_data_array_new" type="<vendor>\<module>\Plugin\Block\Catalog\Product\ImageBuilder" sortOrder="100" disabled="false"/>

File: vendor\module\Plugin\Block\Catalog\Product\ImageBuilder.php


namespace <vendor>\<module>\Plugin\Block\Catalog\Product;

use Magento\Catalog\Model\Product;

class ImageBuilder
     * @param \Magento\Catalog\Block\Product\ImageBuilder $subject
     * @param callable $proceed
     * @return mixed
    public function aroundCreate(
        \Magento\Catalog\Block\Product\ImageBuilder $subject,
        callable $proceed
    ) {
        echo "<pre>";

        return $proceed();

I tried to call plugin but nothing happening and it's calling core function only.

I tried :

  • bin/magento setup:upgrade
  • bin/magento setup:static-content:deploy -f
  • bin/magento setup:di:compile
  • bin/magento index:reindex
  • bin/magento cache:flush

still nothing works. Any help would be appreciated.

2 Answers 2


Please check

If there is any other module is overriding the class by preference.For which you want to add your plugin.

Check if its in developer mode.

Remove the generated/code/ and flush cache

Make sure Module is available in Config.php


You're forgot to pass argument in aroundCreate() and proceed() method. Just use this below code and check log file.


namespace Vendor\Module\Plugin\Block\Catalog\Product;

use Magento\Catalog\Model\Product;

class ImageBuilder {

    public function aroundCreate(
        \Magento\Catalog\Block\Product\ImageBuilder $subject,
        \Closure $proceed,
        \Magento\Catalog\Model\Product $product = null,
        string $imageId = null,
        array $attributes = null
    ) {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/Rohan.log');
        $logger = new \Zend\Log\Logger();
        $logger->info('Your text message');
        return $proceed($product, $imageId, $attributes);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.