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/pdfcustomiser-implementation-m2/src/Block/Pdf/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfcustomiser-implementation-m2/src/Block/Pdf/AddressFormatter.php
<?php
namespace Fooman\PdfCustomiser\Block\Pdf;

use Fooman\PdfCustomiser\Model\System\EmailOptions;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Escaper;
use Magento\Sales\Model\Order\Address\Renderer;

/**
 * Format address for display in pdfs
 *
 * @author     Kristof Ringleff
 * @copyright  Copyright (c) 2009 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.
 */
class AddressFormatter
{
    const XML_PATH_SHOW_EMAIL= 'sales_pdf/all/displaycustomeremail';

    /**
     * @var ScopeConfigInterface
     */
    private $scopeConfig;

    /**
     * @var Renderer
     */
    private $addressRenderer;

    /**
     * @var Escaper
     */
    private $escaper;

    public function __construct(
        ScopeConfigInterface $scopeConfig,
        Renderer $addressRenderer,
        Escaper $escaper
    ) {
        $this->scopeConfig = $scopeConfig;
        $this->addressRenderer = $addressRenderer;
        $this->escaper = $escaper;
    }

    /**
     * @return string
     */
    public function getBillingAddress($order)
    {
        $address = $this->filterAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
        $showEmail = $this->scopeConfig->getValue(
            self::XML_PATH_SHOW_EMAIL,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $order->getStoreId()
        );

        if ($showEmail == EmailOptions::BILLING_ONLY || $showEmail == EmailOptions::BOTH_ADDRESSES) {
            $address .= '<br/>' . $order->getCustomerEmail();
        }
        return $address;
    }

    /**
     * @return string
     */
    public function getShippingAddress($order)
    {
        if ($order->getIsVirtual()) {
            return '';
        }
        $address = $this->filterAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
        $showEmail = $this->scopeConfig->getValue(
            self::XML_PATH_SHOW_EMAIL,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $order->getStoreId()
        );

        if ($showEmail == EmailOptions::SHIPPING_ONLY || $showEmail == EmailOptions::BOTH_ADDRESSES) {
            $address .= '<br/>' . $order->getCustomerEmail();
        }
        return $address;
    }

    /**
     * converts pipe character to linebreak
     * removes empty lines
     *
     * @param string $input
     *
     * @return string
     */
    protected function filterAddress($input)
    {
        $input = $this->escaper->escapeHtml($input, ['br', 'b']);
        $input = str_replace(['|', PHP_EOL], '<br/>', $input);
        return preg_replace('/(<br\s*\/?>\s*)+/', '<br/>', $input);
    }
}

Spamworldpro Mini