0

I installed supro theme on magento2.4.6 project. But I got error like this.

Fatal error: Declaration of MGS\AjaxCart\Block\Product\ImageBuilder::create() must be compatible with Magento\Catalog\Block\Product\ImageBuilder::create(?Magento\Catalog\Model\Product $product = null, ?string $imageId = null, ?array $attributes = null) in /var/www/html/magento2/app/code/MGS/AjaxCart/Block/Product/ImageBuilder.php on line 15

magento2/app/code/MGS/AjaxCart/Block/Product/ImageBuilder.php:

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace MGS\AjaxCart\Block\Product;

class ImageBuilder extends \Magento\Catalog\Block\Product\ImageBuilder
{
    /**
     * Create image block
     *
     * @return \Magento\Catalog\Block\Product\Image
     */
    public function create()
    {
        /** @var \Magento\Catalog\Helper\Image $helper */
        $helper = $this->helperFactory->create()
            ->init($this->product, $this->imageId);

        $template = 'MGS_AjaxCart::product/image_with_borders.phtml';

        $imagesize = $helper->getResizedImageInfo();

        $data = [
            'data' => [
                'template' => $template,
                'image_url' => $helper->getUrl(),
                'width' => $helper->getWidth(),
                'height' => $helper->getHeight(),
                'label' => $helper->getLabel(),
                'ratio' =>  $this->getRatio($helper),
                'custom_attributes' => $this->getCustomAttributes(),
                'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
                'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
            ],
        ];

        return $this->imageFactory->create($data);
    }
}

what is this? How can I fix it?

1 Answer 1

0

Please install latest supro theme, which is compatibility with Magento2.4.6 version.

Because Magento2.4.6 support PHP8.1, so functions require proper arguments while calling the core functions.

Like The file vendor/magento/module-catalog/Block/Product/ImageBuilder.php is declared to use strict types declare(strict_types=1);

If you do not pass a Product but null it throws an TypeError.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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