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/Model/Order/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Chronorelais/Plugin/Model/Order/Shipment.php
<?php
declare(strict_types=1);

namespace Cnc\Chronorelais\Plugin\Model\Order;

class Shipment extends \Chronopost\Chronorelais\Plugin\ShipmentSave
{
    /**
     * @param \Magento\Sales\Model\Order\Shipment $subject
     * @return \Magento\Sales\Model\Order\Shipment|\Magento\Sales\Model\Order\Shipment[]|void
     * @throws \Exception
     */
    public function beforeSave(\Magento\Sales\Model\Order\Shipment $subject)
    {
        $shippingMethodCode = $this->getShippingMethodCode($subject->getOrder()->getData('shipping_method'));

        if ($this->_helperData->isChronoMethod($shippingMethodCode)) {
            return parent::beforeSave($subject);
        }

        return [$subject];
    }

    /**
     * @param \Magento\Sales\Model\Order\Shipment $subject
     * @return \Magento\Sales\Model\Order\Shipment
     */
    public function afterSave(\Magento\Sales\Model\Order\Shipment $subject)
    {
        $shippingMethodCode = $this->getShippingMethodCode($subject->getOrder()->getData('shipping_method'));

        if ($this->_helperData->isChronoMethod($shippingMethodCode)) {
            return parent::afterSave($subject);
        }

        return $subject;
    }

    /**
     * @param mixed $shippingMethod
     * @return string
     */
    private function getShippingMethodCode($shippingMethod): string
    {
        $shippingMethod = explode('_', $shippingMethod);
        return $shippingMethod[1] ?? $shippingMethod[0];
    }
}

Spamworldpro Mini