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/InventoryInventoryShipping/Ui/DataProvider/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/InventoryInventoryShipping/Ui/DataProvider/GetSources.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Ecombricks\InventoryInventoryShipping\Ui\DataProvider;

/**
 * Get source selection data provider sources
 */
class GetSources
{
    
    /**
     * Source management
     * 
     * @var \Ecombricks\Inventory\Model\SourceManagement 
     */
    protected $sourceManagement;
    
    /**
     * Item request factory
     * 
     * @var \Magento\InventorySourceSelectionApi\Api\Data\ItemRequestInterfaceFactory
     */
    protected $itemRequestFactory;
    
    /**
     * Source selection service
     * 
     * @var \Magento\InventorySourceSelectionApi\Api\SourceSelectionServiceInterface
     */
    protected $sourceSelectionService;
    
    /**
     * Get default source selection algorithm code
     * 
     * @var \Magento\InventorySourceSelectionApi\Api\GetDefaultSourceSelectionAlgorithmCodeInterface
     */
    protected $getDefaultSourceSelectionAlgorithmCode;
    
    /**
     * Get inventory request from order
     * 
     * @var \Ecombricks\InventoryInventorySourceSelection\Model\GetInventoryRequestFromOrder 
     */
    protected $getInventoryRequestFromOrder;
    
    /**
     * Constructor
     * 
     * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement
     * @param \Magento\InventorySourceSelectionApi\Api\Data\ItemRequestInterfaceFactory $itemRequestFactory
     * @param \Magento\InventorySourceSelectionApi\Api\SourceSelectionServiceInterface $sourceSelectionService
     * @param \Magento\InventorySourceSelectionApi\Api\GetDefaultSourceSelectionAlgorithmCodeInterface $getDefaultSourceSelectionAlgorithmCode
     * @param \Ecombricks\InventoryInventorySourceSelection\Model\GetInventoryRequestFromOrder $getInventoryRequestFromOrder
     * @return void
     */
    public function __construct(
        \Ecombricks\Inventory\Model\SourceManagement $sourceManagement,
        \Magento\InventorySourceSelectionApi\Api\Data\ItemRequestInterfaceFactory $itemRequestFactory,
        \Magento\InventorySourceSelectionApi\Api\SourceSelectionServiceInterface $sourceSelectionService,
        \Magento\InventorySourceSelectionApi\Api\GetDefaultSourceSelectionAlgorithmCodeInterface $getDefaultSourceSelectionAlgorithmCode,
        \Ecombricks\InventoryInventorySourceSelection\Model\GetInventoryRequestFromOrder $getInventoryRequestFromOrder
    )
    {
        $this->sourceManagement = $sourceManagement;
        $this->itemRequestFactory = $itemRequestFactory;
        $this->sourceSelectionService = $sourceSelectionService;
        $this->getDefaultSourceSelectionAlgorithmCode = $getDefaultSourceSelectionAlgorithmCode;
        $this->getInventoryRequestFromOrder = $getInventoryRequestFromOrder;
    }
    
    /**
     * Execute
     * 
     * @param int $orderId
     * @param int $orderItemId
     * @param string $sku
     * @param float $qty
     * @return array
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function execute(int $orderId, int $orderItemId, string $sku, float $qty): array
    {
        $itemRequest = $this->itemRequestFactory->create(['sku' => $sku, 'qty' => $qty]);
        $itemRequest->getExtensionAttributes()->setOrderItemId($orderItemId);
        $inventoryRequest = $this->getInventoryRequestFromOrder->execute($orderId, [$itemRequest]);
        $sourceSelectionResult = $this->sourceSelectionService->execute(
            $inventoryRequest,
            $this->getDefaultSourceSelectionAlgorithmCode->execute()
        );
        $result = [];
        foreach ($sourceSelectionResult->getSourceSelectionItems() as $item) {
            $sourceCode = $item->getSourceCode();
            $result[] = [
                'sourceName' => $this->sourceManagement->getSourceName($sourceCode),
                'sourceCode' => $sourceCode,
                'qtyAvailable' => $item->getQtyAvailable(),
                'qtyToDeduct' => $item->getQtyToDeduct(),
            ];
        }
        return $result;
    }
    
}

Spamworldpro Mini