|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * GiaPhuGroup Co., Ltd. |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the GiaPhuGroup.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * https://www.giaphugroup.com/LICENSE.txt |
| 10 | + * |
| 11 | + * DISCLAIMER |
| 12 | + * |
| 13 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 14 | + * version in the future. |
| 15 | + * |
| 16 | + * @category PHPCuong |
| 17 | + * @package PHPCuong_LazyLoadingImage |
| 18 | + * @copyright Copyright (c) 2019-2020 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/) |
| 19 | + * @license https://www.giaphugroup.com/LICENSE.txt |
| 20 | + */ |
| 21 | + |
| 22 | +namespace PHPCuong\LazyLoadingImage\Override\Catalog\Block\Product; |
| 23 | + |
| 24 | +class ImageBuilder extends \Magento\Catalog\Block\Product\ImageBuilder |
| 25 | +{ |
| 26 | + /** |
| 27 | + * Create image block |
| 28 | + * |
| 29 | + * @return \Magento\Catalog\Block\Product\Image |
| 30 | + */ |
| 31 | + public function create() |
| 32 | + { |
| 33 | + /** @var \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface $simpleOption */ |
| 34 | + $simpleOption = $this->product->getOptionById('simple_product'); |
| 35 | + |
| 36 | + if ($simpleOption !== null) { |
| 37 | + $optionProduct = $simpleOption->getProduct(); |
| 38 | + $this->setProduct($optionProduct); |
| 39 | + } |
| 40 | + |
| 41 | + /** @var \Magento\Catalog\Helper\Image $helper */ |
| 42 | + $helper = $this->helperFactory->create() |
| 43 | + ->init($this->product, $this->imageId); |
| 44 | + |
| 45 | + $template = $helper->getFrame() |
| 46 | + ? 'PHPCuong_LazyLoadingImage::product/image.phtml' |
| 47 | + : 'PHPCuong_LazyLoadingImage::product/image_with_borders.phtml'; |
| 48 | + |
| 49 | + try { |
| 50 | + $imagesize = $helper->getResizedImageInfo(); |
| 51 | + } catch (NotLoadInfoImageException $exception) { |
| 52 | + $imagesize = [$helper->getWidth(), $helper->getHeight()]; |
| 53 | + } |
| 54 | + |
| 55 | + $data = [ |
| 56 | + 'data' => [ |
| 57 | + 'template' => $template, |
| 58 | + 'image_url' => $helper->getUrl(), |
| 59 | + 'width' => $helper->getWidth(), |
| 60 | + 'height' => $helper->getHeight(), |
| 61 | + 'label' => $helper->getLabel(), |
| 62 | + 'ratio' => $this->getRatio($helper), |
| 63 | + 'custom_attributes' => $this->getCustomAttributes(), |
| 64 | + 'resized_image_width' => $imagesize[0], |
| 65 | + 'resized_image_height' => $imagesize[1], |
| 66 | + 'product_id' => $this->product->getId() |
| 67 | + ], |
| 68 | + ]; |
| 69 | + |
| 70 | + return $this->imageFactory->create($data); |
| 71 | + } |
| 72 | +} |
0 commit comments