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/InventoryInventorySourceSelection/Model/Algorithms/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/Ecombricks/InventoryInventorySourceSelection/Model/Algorithms/DefaultAlgorithm.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Ecombricks\InventoryInventorySourceSelection\Model\Algorithms;

/**
 * Default source selection algorithm
 */
class DefaultAlgorithm implements \Magento\InventorySourceSelectionApi\Model\SourceSelectionInterface
{
    
    /**
     * Get sources assigned to stock ordered by priority
     * 
     * @var \Magento\InventoryApi\Api\GetSourcesAssignedToStockOrderedByPriorityInterface
     */
    protected $getSourcesAssignedToStockOrderedByPriority;
    
    /**
     * Get default sorted sources result
     * 
     * @var \Ecombricks\InventoryInventorySourceSelection\Model\Algorithms\Result\GetDefaultSortedSourcesResult 
     */
    protected $getDefaultSortedSourcesResult;
    
    /**
     * Constructor
     * 
     * @param \Magento\InventoryApi\Api\GetSourcesAssignedToStockOrderedByPriorityInterface $getSourcesAssignedToStockOrderedByPriority
     * @param \Ecombricks\InventoryInventorySourceSelection\Model\Algorithms\Result\GetDefaultSortedSourcesResult $getDefaultSortedSourcesResult
     * @retun void
     */
    public function __construct(
        \Magento\InventoryApi\Api\GetSourcesAssignedToStockOrderedByPriorityInterface $getSourcesAssignedToStockOrderedByPriority,
        \Ecombricks\InventoryInventorySourceSelection\Model\Algorithms\Result\GetDefaultSortedSourcesResult $getDefaultSortedSourcesResult
    )
    {
        $this->getSourcesAssignedToStockOrderedByPriority = $getSourcesAssignedToStockOrderedByPriority;
        $this->getDefaultSortedSourcesResult = $getDefaultSortedSourcesResult;
    }
    
    /**
     * Get enabled sources ordered by priority
     *
     * @param int $stockId
     * @return \Magento\InventoryApi\Api\Data\SourceInterface[]
     * @throws \Magento\Framework\Exception\InputException
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    protected function getEnabledSourcesOrderedByPriority(int $stockId): array
    {
        return array_filter(
            $this->getSourcesAssignedToStockOrderedByPriority->execute($stockId),
            function (\Magento\InventoryApi\Api\Data\SourceInterface $source) {
                return $source->isEnabled();
            }
        );
    }
    
    /**
     * Execute
     * 
     * @param \Magento\InventorySourceSelectionApi\Api\Data\InventoryRequestInterface $inventoryRequest
     * @return \Magento\InventorySourceSelectionApi\Api\Data\SourceSelectionResultInterface
     */
    public function execute(
        \Magento\InventorySourceSelectionApi\Api\Data\InventoryRequestInterface $inventoryRequest
    ): \Magento\InventorySourceSelectionApi\Api\Data\SourceSelectionResultInterface
    {
        
        $sortedSources = $this->getEnabledSourcesOrderedByPriority($inventoryRequest->getStockId());
        $inventoryRequestExtension = $inventoryRequest->getExtensionAttributes();
        $inventoryRequestExtension->setIsDefault(true);
        $sourceSelectionResult = $this->getDefaultSortedSourcesResult->execute($inventoryRequest, $sortedSources);
        $inventoryRequestExtension->setIsDefault(false);
        return $sourceSelectionResult;
    }
    
}

Spamworldpro Mini