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/Ecombricks/InventorySales/Plugin/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/InventorySales/Plugin/Model/Order.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Ecombricks\InventorySales\Plugin\Model;

/**
 * Order model plugin
 */
class Order
{

    /**
     * Shipping method full code
     *
     * @var \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode
     */
    protected $shippingMethodFullCode;

    /**
     * Constructor
     *
     * @param \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode $shippingMethodFullCode
     * @return void
     */
    public function __construct(
        \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode $shippingMethodFullCode
    )
    {
        $this->shippingMethodFullCode = $shippingMethodFullCode;
    }

    /**
     * Around get shipping method
     *
     * @param \Magento\Sales\Model\Order $subject
     * @param \Closure $proceed
     * @param bool $asObject
     * @return array|\Magento\Framework\DataObject
     */
    public function aroundGetShippingMethod(
        \Magento\Sales\Model\Order $subject,
        \Closure $proceed,
        $asObject = false
    )
    {
        $shippingMethods = $subject->inventoryGetShippingMethod();
        if (!$asObject) {
            return $shippingMethods;
        } else {
            $carrierCodes = $methodCodes = [];
            foreach ($shippingMethods as $sourceCode => $shippingMethod) {
                $shippingMethodPieces = $this->shippingMethodFullCode->parse($shippingMethod);
                $carrierCodes[$sourceCode] = $shippingMethodPieces[0];
                $methodCodes[$sourceCode] = !empty($shippingMethodPieces[1]) ? $shippingMethodPieces[1] : '';
            }
            return new \Magento\Framework\DataObject(['carrier_code' => $carrierCodes, 'method' => $methodCodes]);
        }
    }

    /**
     * Around set data
     *
     * @param \Magento\Sales\Model\Order $subject
     * @param \Closure $proceed
     * @param array|string $key
     * @param null $value
     * @return \Magento\Sales\Model\Order
     */
    public function aroundSetData(
        \Magento\Sales\Model\Order $subject,
        \Closure $proceed,
        $key,
        $value = null
    )
    {
        if (is_array($key) && array_key_exists('shipping_method', $key)) {
            $proceed($key, $value);
            return $subject->inventorySetShippingMethod($key['shipping_method']);
        } else if (is_string($key) && $key === 'shipping_method') {
            return $subject->inventorySetShippingMethod($value);
        }
        return $proceed($key, $value);
    }

}

Spamworldpro Mini