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/InventoryCheckout/Plugin/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

/**
 * Checkout default configuration provider plugin
 */
class DefaultConfigProvider
{
    
    /**
     * Checkout session
     * 
     * @var \Magento\Checkout\Model\Session
     */
    protected $checkoutSession;
    
    /**
     * Shipping method manager
     * 
     * @var \Ecombricks\InventoryQuote\Api\ShippingMethodManagementInterface
     */
    protected $shippingMethodManager;
    
    /**
     * Source management
     * 
     * @var \Ecombricks\Inventory\Model\SourceManagement 
     */
    protected $sourceManagement;
    
    /**
     * Quote
     * 
     * @var \Magento\Quote\Model\Quote
     */
    protected $quote;
    
    /**
     * Constructor
     * 
     * @param \Magento\Checkout\Model\Session $checkoutSession
     * @param \Ecombricks\InventoryQuote\Api\ShippingMethodManagementInterface $shippingMethodManager
     * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement
     * @return void
     */
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        \Ecombricks\InventoryQuote\Api\ShippingMethodManagementInterface $shippingMethodManager,
        \Ecombricks\Inventory\Model\SourceManagement $sourceManagement
    )
    {
        $this->checkoutSession = $checkoutSession;
        $this->shippingMethodManager = $shippingMethodManager;
        $this->sourceManagement = $sourceManagement;
    }
    
    /**
     * Get active quote
     *
     * @return \Magento\Quote\Model\Quote
     */
    protected function getQuote()
    {
        if ($this->quote !== null) {
            return $this->quote;
        }
        $this->quote = $this->checkoutSession->getQuote();
        return $this->quote;
    }
    
    /**
     * Get sources
     * 
     * @return array
     */
    protected function getSources()
    {
        $sources = [];
        $quoteSourceCodes = $this->getQuote()->getSourceCodes();
        foreach ($this->sourceManagement->getCurrentSources() as $source) {
            $sourceCode = $source->getSourceCode();
            if (!in_array($sourceCode, $quoteSourceCodes)) {
                continue;
            }
            $sources[] = [ 'source_code' => $sourceCode, 'name' => $source->getName(), ];
        }
        return $sources;
    }
    
    /**
     * Get selected shipping methods
     * 
     * @return array
     */
    protected function getSelectedShippingMethods()
    {
        $output = [];
        try {
            $quoteId = $this->getQuote()->getId();
            $shippingMethods = $this->shippingMethodManager->inventoryGet($quoteId);
            if (empty($shippingMethods)) {
                return $output;
            }
            foreach ($shippingMethods as $shippingMethod) {
                $output[] = $shippingMethod->__toArray();
            }
        } catch (\Exception $exception) {
            $output = [];
        }
        return $output;
    }
    
    /**
     * Around get config
     * 
     * @param \Magento\Checkout\Model\DefaultConfigProvider $subject
     * @param \Closure $proceed
     * @return array|mixed
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function aroundGetConfig(
        \Magento\Checkout\Model\DefaultConfigProvider $subject,
        \Closure $proceed
    )
    {
        $result = $proceed();
        $result['selectedShippingMethod'] = $this->getSelectedShippingMethods();
        $result['quoteData']['sources'] = $this->getSources();
        return $result;
    }
    
}

Spamworldpro Mini