Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored code #27758

Merged
merged 6 commits into from
Aug 14, 2020
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}