From bde04b0e514981b4c21e870b743e992570f36048 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Wed, 15 Jul 2020 17:17:05 -0400 Subject: [PATCH] Fix issue with Magento 2.4 --- Plugin/Block/Product/ImagePlugin.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Plugin/Block/Product/ImagePlugin.php b/Plugin/Block/Product/ImagePlugin.php index 149a422..e66e236 100644 --- a/Plugin/Block/Product/ImagePlugin.php +++ b/Plugin/Block/Product/ImagePlugin.php @@ -7,6 +7,7 @@ namespace MagePal\CatalogLazyLoad\Plugin\Block\Product; +use Closure; use Magento\Catalog\Block\Product\Image; use MagePal\CatalogLazyLoad\Helper\Data; @@ -30,18 +31,26 @@ public function __construct( /** * @param Image $subject - * @param \Closure $proceed + * @param Closure $proceed * @return mixed */ - public function aroundToHtml(Image $subject, \Closure $proceed) + public function aroundToHtml(Image $subject, Closure $proceed) { if ($this->helper->isEnabled() && $this->helper->applyLazyLoad()) { $orgImageUrl = $subject->getImageUrl(); $subject->setImageUrl(''); - $customAttributes = trim( - $subject->getCustomAttributes() . 'magepal-data-original' - ); + //Magento 2.4.0 + if (is_array($subject->getCustomAttributes())) { + $customAttributes = array_merge( + $subject->getCustomAttributes(), + ['magepal-data-original' => 'placeholder'] + ); + } else { + $customAttributes = trim( + $subject->getCustomAttributes() . 'magepal-data-original' + ); + } $subject->setCustomAttributes($customAttributes); @@ -49,12 +58,14 @@ public function aroundToHtml(Image $subject, \Closure $proceed) $find = [ 'img class="', + 'magepal-data-original="placeholder"', 'magepal-data-original' ]; $replace = [ 'img class="lazy swatch-option-loading ', sprintf(' data-original="%s"', $orgImageUrl), + sprintf(' data-original="%s"', $orgImageUrl) ]; return str_replace($find, $replace, $result);