Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/fooman/pdfcore-m2/src/Block/Pdf/Column/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfcore-m2/src/Block/Pdf/Column/Image.php
<?php
/**
 * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz)
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Fooman\PdfCore\Block\Pdf\Column;

use Fooman\PdfCore\Helper\FileOps;

class Image extends \Fooman\PdfCore\Block\Pdf\Column implements \Fooman\PdfCore\Block\Pdf\ColumnInterface
{
    public const DEFAULT_WIDTH = 18;
    public const COLUMN_TYPE = 'fooman_image';

    /**
     * @var \Magento\Catalog\Model\ResourceModel\Product
     */
    protected $productResource;

    /**
     * @var \Magento\Catalog\Model\ProductRepository
     */
    protected $productRepository;

    /**
     * @var FileOps
     */
    protected $file;

    /**
     * @var \Fooman\PdfCore\Helper\ParamKey
     */
    protected $paramKeyHelper;

    /**
     * @param \Magento\Backend\Block\Template\Context         $context
     * @param \Magento\Catalog\Model\ResourceModel\Product    $productResource
     * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
     * @param FileOps                                         $file
     * @param \Fooman\PdfCore\Helper\ParamKey                 $paramKeyHelper
     * @param array                                           $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Catalog\Model\ResourceModel\Product $productResource,
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
        FileOps $file,
        \Fooman\PdfCore\Helper\ParamKey $paramKeyHelper,
        array $data = []
    ) {
        $this->productResource = $productResource;
        $this->productRepository = $productRepository;
        $this->paramKeyHelper = $paramKeyHelper;
        $this->file = $file;
        parent::__construct($context, $data);
    }

    public function getGetter()
    {
        return [$this, 'getImage'];
    }

    /**
     * @param $row
     *
     * @return string
     */
    public function getImage($row)
    {
        $dim = $this->getImageDimensions();
        $imagePath = $this->getImagePath($row);
        if ($imagePath) {
            $params = [
                $imagePath,
                '',
                '',
                $this->getMaxImageWidth($row),
                $dim['image'],
                '',
                '',
                '',
                true,
                300,
                '',
                false,
                false,
                0,
                true
            ];
            return sprintf(
                '<div align="%s"><tcpdf method="Image" %s /></div><span style="line-height:%s;"></span>',
                $this->getAlignment() ? $this->getAlignment() : 'left',
                $this->paramKeyHelper->getEncodedParams($params),
                $dim['spacer']
            );
        }

        return '';
    }

    private function getMaxImageWidth($row)
    {
        return ($this->getAvailablePageWidth($row->getStoreId()) * $this->getCalculatedWidth()/100);
    }

    private function getImageDimensions($size = 'default')
    {
        $sizes = [
            'large'      => ['image' => '25', 'spacer' => '25mm'],
            'xtra-large' => ['image' => '40', 'spacer' => '40mm'],
            'default'    => ['image' => '15', 'spacer' => '15mm'],
            'small'      => ['image' => '12', 'spacer' => '12mm']
        ];
        if (isset($sizes[$size])) {
            return $sizes[$size];
        }
        return $sizes['default'];
    }

    /**
     * @param $row
     *
     * @return bool|string
     */
    public function getImagePath($row)
    {
        $imagePath = false;
        $attribute = $this->productResource->getAttribute('image');
        $orderItem = $this->getOrderItem($row);
        if ($orderItem->getProductType() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE
            && $orderItem->getProductOptionByCode('simple_sku')) {
            try {
                $product = $this->productRepository->get(
                    $orderItem->getProductOptionByCode('simple_sku'),
                    false,
                    $row->getStoreId()
                );
                $imagePath = $attribute->getFrontend()->getValue($product);
            } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                $imagePath = false;
            }
        }

        //fallback on main configurable if no image is found on simple product above
        if ((!$imagePath) || ($imagePath === 'no_selection')) {
            try {
                $product = $this->productRepository->getById($orderItem->getProductId(), false, $row->getStoreId());
                $imagePath = $attribute->getFrontend()->getValue($product);
            } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                $imagePath = false;
            }
        }

        //We might still have a chance of picking up an image from a grouped parent product
        if ((!$imagePath) || ($imagePath === 'no_selection')) {
            $productOptions = $orderItem->getProductOptions();
            if (isset($productOptions['super_product_config']['product_id'])) {
                $productId = $productOptions['super_product_config']['product_id'];
                try {
                    $product = $this->productRepository->getById($productId, false, $row->getStoreId());
                    $imagePath = $attribute->getFrontend()->getValue($product);
                } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                    $imagePath = false;
                }
            }
        }

        if ($imagePath) {
            $fullPath = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
                ->getAbsolutePath('/catalog/product/' . ltrim($imagePath, '/'));
            if ($this->file->fileExists($fullPath)) {
                return $fullPath;
            }
        }
        return false;
    }
}

Spamworldpro Mini