![]() 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/InventoryInventorySales/Model/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ declare(strict_types=1); namespace Ecombricks\InventoryInventorySales\Model; /** * Get product salable qty model */ class GetProductSalableQty implements \Ecombricks\InventoryInventorySales\Api\GetProductSalableQtyInterface { /** * Source manager * * @var \Ecombricks\Inventory\Model\SourceManagement */ protected $sourceManagement; /** * Product management * * @var \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement */ protected $productManagement; /** * Source item management * * @var \Ecombricks\InventoryInventorySales\Model\SourceItemManagement */ protected $sourceItemManagement; /** * Get stock item configuration * * @var \Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface */ protected $getStockItemConfiguration; /** * Get reservations quantity * * @var \Ecombricks\InventoryInventoryReservations\Model\GetReservationsQuantityInterface */ protected $getReservationsQuantity; /** * @var \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface */ protected $getProductTypesBySkus; /** * Constructor * * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement * @param \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement $productManagement * @param \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement * @param \Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfig * @param \Ecombricks\InventoryInventoryReservations\Model\GetReservationsQuantityInterface $getReservationsQuantity * @param \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface $getProductTypesBySkus * @return void */ public function __construct( \Ecombricks\Inventory\Model\SourceManagement $sourceManagement, \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement $productManagement, \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement, \Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfig, \Ecombricks\InventoryInventoryReservations\Model\GetReservationsQuantityInterface $getReservationsQuantity, \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface $getProductTypesBySkus ) { $this->sourceManagement = $sourceManagement; $this->productManagement = $productManagement; $this->sourceItemManagement = $sourceItemManagement; $this->getStockItemConfiguration = $getStockItemConfig; $this->getReservationsQuantity = $getReservationsQuantity; $this->getProductTypesBySkus = $getProductTypesBySkus; } /** * Validate product type * * @param string $sku * @return bool * @throws \Magento\Framework\Exception\InputException */ protected function validateProductType(string $sku): bool { $productType = $this->getProductTypesBySkus->execute([$sku])[$sku]; if (!$this->productManagement->isSourceItemManagementAllowedByProductType($productType)) { throw new \Magento\Framework\Exception\InputException( __('Can\'t check requested quantity for products without source items support.') ); } return true; } /** * Execute * * @param string $sku * @param string $sourceCode * @return float * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(string $sku, string $sourceCode): float { $this->validateProductType($sku); $stockId = $this->sourceManagement->getSourceStockId($sourceCode); $sourceItem = $this->sourceItemManagement->get($sku, $stockId, $sourceCode); if (!$sourceItem || !$sourceItem->isSalable()) { return 0; } $stockItemConfig = $this->getStockItemConfiguration->execute($sku, $stockId); $qty = $sourceItem->getQuantity(); $reservationQty = $this->getReservationsQuantity->execute($sku, $sourceCode); $minQty = $stockItemConfig->getMinQty(); return $qty + $reservationQty - $minQty; } }