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

Fix bool scope config and update throws and update use clases #18065

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\Search\Model\QueryInterface;
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;

/**
* Class DataProvider
*/
class DataProvider implements SuggestedQueriesInterface
{
/**
Expand Down Expand Up @@ -51,6 +54,8 @@ class DataProvider implements SuggestedQueriesInterface
private $recommendationsFactory;

/**
* DataProvider constructor.
*
* @param ScopeConfigInterface $scopeConfig
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
* @param \Magento\AdvancedSearch\Model\ResourceModel\RecommendationsFactory $recommendationsFactory
Expand All @@ -69,18 +74,24 @@ public function __construct(
}

/**
* Is Results Count Enabled
*
* @return bool
*/
public function isResultsCountEnabled()
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::CONFIG_RESULTS_COUNT_ENABLED,
ScopeInterface::SCOPE_STORE
);
}

/**
* {@inheritdoc}
* Get Items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the comment and just remove curly braces {}. Please refer to the guide https://devdocs.magento.com/guides/v2.3/coding-standards/docblock-standard-general.html#inheritdoc

*
* @param QueryInterface $query
*
* @return array|\Magento\Search\Model\QueryResult[]
*/
public function getItems(QueryInterface $query)
{
Expand All @@ -102,6 +113,8 @@ public function getItems(QueryInterface $query)
}

/**
* Return Search Recommendations
*
* @param QueryInterface $query
* @return array
*/
Expand All @@ -126,17 +139,21 @@ private function getSearchRecommendations(\Magento\Search\Model\QueryInterface $
}

/**
* Is Search Recommendations Enabled
*
* @return bool
*/
private function isSearchRecommendationsEnabled()
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::CONFIG_IS_ENABLED,
ScopeInterface::SCOPE_STORE
);
}

/**
* Return Search Recommendations Count
*
* @return int
*/
private function getSearchRecommendationsCount()
Expand Down
58 changes: 40 additions & 18 deletions app/code/Magento/CatalogInventory/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\CatalogInventory\Helper\Minsaleqty as MinsaleqtyHelper;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
Expand Down Expand Up @@ -131,6 +132,8 @@ class Configuration implements StockConfigurationInterface
protected $storeManager;

/**
* Configuration constructor.
*
* @param ConfigInterface $config
* @param ScopeConfigInterface $scopeConfig
* @param MinsaleqtyHelper $minsaleqtyHelper
Expand All @@ -149,7 +152,9 @@ public function __construct(
}

/**
* {@inheritdoc}
* Default Scope Id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the comment and just remove curly braces {}. Please refer to the guide https://devdocs.magento.com/guides/v2.3/coding-standards/docblock-standard-general.html#inheritdoc

*
* @return int
*/
public function getDefaultScopeId()
{
Expand All @@ -159,6 +164,8 @@ public function getDefaultScopeId()
}

/**
* Is Qty Type Ids
*
* @param int|null $filter
* @return array
*/
Expand All @@ -182,6 +189,8 @@ public function getIsQtyTypeIds($filter = null)
}

/**
* Is Qty
*
* @param int $productTypeId
* @return bool
*/
Expand All @@ -201,25 +210,29 @@ public function canSubtractQty($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_CAN_SUBTRACT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Min Qty
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return float
*/
public function getMinQty($store = null)
{
return (float)$this->scopeConfig->getValue(
self::XML_PATH_MIN_QTY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Min Sale Qty
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @param int $customerGroupId
* @return float
Expand All @@ -230,27 +243,31 @@ public function getMinSaleQty($store = null, $customerGroupId = null)
}

/**
* Get Max Sale Qty
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return float|null
*/
public function getMaxSaleQty($store = null)
{
return (float)$this->scopeConfig->getValue(
self::XML_PATH_MAX_SALE_QTY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Notify Stock Qty
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return float
*/
public function getNotifyStockQty($store = null)
{
return (float) $this->scopeConfig->getValue(
self::XML_PATH_NOTIFY_STOCK_QTY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -264,22 +281,24 @@ public function getNotifyStockQty($store = null)
*/
public function getEnableQtyIncrements($store = null)
{
return (bool) $this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ENABLE_QTY_INCREMENTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Qty Increments
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return float
*/
public function getQtyIncrements($store = null)
{
return (float)$this->scopeConfig->getValue(
self::XML_PATH_QTY_INCREMENTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -294,7 +313,7 @@ public function getBackorders($store = null)
{
return (int) $this->scopeConfig->getValue(
self::XML_PATH_BACKORDERS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -309,7 +328,7 @@ public function getManageStock($store = null)
{
return (int) $this->scopeConfig->isSetFlag(
self::XML_PATH_MANAGE_STOCK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -325,7 +344,7 @@ public function getCanBackInStock($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_CAN_BACK_IN_STOCK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -340,7 +359,7 @@ public function isShowOutOfStock($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_SHOW_OUT_OF_STOCK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand All @@ -355,14 +374,13 @@ public function isAutoReturnEnabled($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ITEM_AUTO_RETURN,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get 'Display product stock status' option value
* Shows if it is necessary to show product stock status ('in stock'/'out of stock')
* Display product stock status. Shows if it is necessary to show product stock status in stock/out of stock.
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return bool
Expand All @@ -371,12 +389,14 @@ public function isDisplayProductStockStatus($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Default Config Value
*
* @param string $field
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return string|null
Expand All @@ -385,20 +405,22 @@ public function getDefaultConfigValue($field, $store = null)
{
return $this->scopeConfig->getValue(
self::XML_PATH_ITEM . $field,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get Stock Threshold Qty
*
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return string|null
*/
public function getStockThresholdQty($store = null)
{
return $this->scopeConfig->getValue(
self::XML_PATH_STOCK_THRESHOLD_QTY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testGetEnableQtyIncrements()
$store = 1;

$this->scopeConfigMock->expects($this->once())
->method('getValue')
->method('isSetFlag')
->with(
Configuration::XML_PATH_ENABLE_QTY_INCREMENTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Expand Down
Loading