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/Cnc/Chronorelais/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Cnc/Chronorelais/Plugin/PaymentInformationManagement.php
<?php
/**
 * Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Krzysztof Majkowski <[email protected]> <[email protected]>
 */

declare(strict_types=1);

namespace Cnc\Chronorelais\Plugin;

use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\Exception\StateException;
use Magento\Quote\Api\CartRepositoryInterface;

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;
    }

    /**
     * Plugin overridden because $shippingAddress->getShippingMethod() returns array in Ecombriks module.
     *
     * @param $subject
     * @param $cartId
     * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
     * @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
     * @throws StateException
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function beforeSavePaymentInformationAndPlaceOrder(
        $subject,
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {
        $quote = $this->_quoteRepository->getActive($cartId);
        $shippingAddress = $quote->getShippingAddress();
        $shippingMethod = $shippingAddress->getShippingMethod();

        /* Si mode RDV et pas de session : on affiche erreur */
        if (is_array($shippingMethod)) {
            foreach ($shippingMethod as $source => $method) {
                $this->check($method);
            }
        } else {
            $this->check($shippingMethod);
        }
    }

    /**
     * @param $shippingMethod
     * @throws StateException
     */
    private function check($shippingMethod)
    {
        if (preg_match(
            '/chronopostsrdv/',
            $shippingMethod,
            $matches,
            PREG_OFFSET_CAPTURE
        ) && !$this->_checkoutSession->getData('chronopostsrdv_creneaux_info')) {
            throw new StateException(__('Please select an appointment date'));
        }
    }
}

Spamworldpro Mini