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/Renderer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfcore-m2/src/Block/Pdf/Column/Renderer/ProductAttribute.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\Renderer;

use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\DataObject;
use Magento\Framework\Pricing\PriceCurrencyInterface;

class ProductAttribute extends AbstractRenderer
{
    private $currencyFormatter;

    public function __construct(
        Context $context,
        PriceCurrencyInterface $priceCurrency,
        array $data = []
    ) {
        $this->currencyFormatter = $priceCurrency;
        parent::__construct($context, $data);
    }

    /**
     * Renders grid column
     *
     * @param DataObject $row
     *
     * @return mixed
     */
    // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Magento 2 Core use
    public function _getValue(DataObject $row)
    {
        $value = parent::_getValue($row);
        if (is_array($value) && isset($value['render_as_currency'])) {
            return $this->renderAsCurrency($row, $value['value']);
        }

        return $this->escapeHtml($value, ['br']);
    }

    private function renderAsCurrency($row, $value)
    {
        if (is_array($value)) {
            $output = [];
            foreach ($value as $price) {
                if ($price['amount'] !== null) {
                    $output[] = $this->currencyFormatter->format(
                        $price['amount'],
                        false,
                        PriceCurrencyInterface::DEFAULT_PRECISION,
                        null,
                        $price['currency']
                    );
                }
            }
            return implode('<br/>', $output);
        }

        if ($value) {
            return $this->currencyFormatter->format(
                $value,
                false,
                PriceCurrencyInterface::DEFAULT_PRECISION,
                null,
                $this->getCurrencyCode($row)
            );
        }
    }

    private function getCurrencyCode($row)
    {
        if ($code = $this->getColumn()->getCurrencyCode()) {
            return $code;
        }
        if ($code = $row->getData($this->getColumn()->getCurrency())) {
            return $code;
        }
        return null;
    }
}

Spamworldpro Mini