Skip to content

Commit

Permalink
ENGCOM-7979: refactored code #27758
Browse files Browse the repository at this point in the history
 - Merge Pull Request #27758 from ProkopovVitaliy/magento2:fix-26702
 - Merged commits:
   1. e527114
   2. 677ddce
   3. 7199dfe
   4. 6d024bb
   5. 707297a
   6. e035f6a
  • Loading branch information
magento-engcom-team committed Aug 13, 2020
2 parents c415874 + e035f6a commit f7e4b2a
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions app/code/Magento/CatalogInventory/Model/StockState.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
use Magento\CatalogInventory\Api\StockStateInterface;
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface;
use Magento\Framework\DataObject;

/**
* Provides functionality for stock state information
*
* Interface StockState
*/
class StockState implements StockStateInterface
Expand All @@ -31,6 +34,8 @@ class StockState implements StockStateInterface
protected $stockConfiguration;

/**
* StockState constructor
*
* @param StockStateProviderInterface $stockStateProvider
* @param StockRegistryProviderInterface $stockRegistryProvider
* @param StockConfigurationInterface $stockConfiguration
Expand All @@ -46,30 +51,32 @@ public function __construct(
}

/**
* Verify stock by product id
*
* @param int $productId
* @param int $scopeId
* @return bool
*/
public function verifyStock($productId, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->verifyStock($stockItem);
}

/**
* Verify notification by product id
*
* @param int $productId
* @param int $scopeId
* @return bool
*/
public function verifyNotification($productId, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->verifyNotification($stockItem);
}

Expand All @@ -84,16 +91,14 @@ public function verifyNotification($productId, $scopeId = null)
*/
public function checkQty($productId, $qty, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->checkQty($stockItem, $qty);
}

/**
* Returns suggested qty that satisfies qty increments and minQty/maxQty/minSaleQty/maxSaleQty conditions
* or original qty if such value does not exist
* Returns suggested qty that satisfies qty increments/minQty/maxQty/minSaleQty/maxSaleQty else returns original qty
*
* @param int $productId
* @param float $qty
Expand All @@ -102,10 +107,9 @@ public function checkQty($productId, $qty, $scopeId = null)
*/
public function suggestQty($productId, $qty, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->suggestQty($stockItem, $qty);
}

Expand All @@ -118,29 +122,31 @@ public function suggestQty($productId, $qty, $scopeId = null)
*/
public function getStockQty($productId, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->getStockQty($stockItem);
}

/**
* Check qty increments by product id
*
* @param int $productId
* @param float $qty
* @param int $websiteId
* @return \Magento\Framework\DataObject
* @return DataObject
*/
public function checkQtyIncrements($productId, $qty, $websiteId = null)
{
// if ($websiteId === null) {
$websiteId = $this->stockConfiguration->getDefaultScopeId();
// }
$websiteId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);

return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty);
}

/**
* Check quote item qty
*
* @param int $productId
* @param float $itemQty
* @param float $qtyToCheck
Expand All @@ -150,10 +156,9 @@ public function checkQtyIncrements($productId, $qty, $websiteId = null)
*/
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
{
// if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
// }
$scopeId = $this->stockConfiguration->getDefaultScopeId();
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);

return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
}
}

0 comments on commit f7e4b2a

Please sign in to comment.