99 $this->_scopeConfig = $scopeConfig;
112 $this->
_init(
'cataloginventory_stock',
'stock_id');
127 $itemTable = $this->
getTable(
'cataloginventory_stock_item');
133 $productTable = $this->
getTable(
'catalog_product_entity');
134 $selectProducts = $this->
getConnection()->select()->from([
'p' => $productTable], [])
138 'product_id' =>
'entity_id',
139 'type_id' =>
'type_id',
145 $items[$si[
'product_id']] = $si;
147 foreach ($this->
getConnection()->fetchAll($selectProducts) as $p) {
148 $items[$p[
'product_id']][
'type_id'] = $p[
'type_id'];
172 $where = [
'product_id IN (?)' => array_keys(
$items),
'website_id = ?' =>
$websiteId];
186 if (!$this->_isConfig) {
194 foreach ($configMap as $field => $const) {
195 $this->{$field} = (int) $this->_scopeConfig->getValue(
197 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
201 $this->_isConfig =
true;
202 $this->_configTypeIds = array_keys($this->stockConfiguration->getIsQtyTypeIds(
true));
217 $websiteId = $this->stockConfiguration->getDefaultScopeId();
220 $values = [
'is_in_stock' => 0,
'stock_status_changed_auto' => 1];
223 ->where(
'type_id IN(?)', $this->_configTypeIds);
226 'website_id = %1$d' .
227 ' AND is_in_stock = 1' .
228 ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' .
229 ' AND ((use_config_backorders = 1 AND %3$d = %4$d) OR (use_config_backorders = 0 AND backorders = %3$d))' .
230 ' AND ((use_config_min_qty = 1 AND qty <= %5$d) OR (use_config_min_qty = 0 AND qty <= min_qty))' .
231 ' AND product_id IN (%6$s)',
233 $this->_isConfigManageStock,
235 $this->_isConfigBackorders,
236 $this->_configMinQty,
254 $websiteId = $this->stockConfiguration->getDefaultScopeId();
257 $values = [
'is_in_stock' => 1];
260 ->where(
'type_id IN(?)', $this->_configTypeIds);
263 'website_id = %1$d' .
264 ' AND is_in_stock = 0' .
265 ' AND stock_status_changed_auto = 1' .
266 ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' .
267 ' AND ((use_config_min_qty = 1 AND qty > %3$d) OR (use_config_min_qty = 0 AND qty > min_qty))' .
268 ' AND product_id IN (%4$s)',
270 $this->_isConfigManageStock,
271 $this->_configMinQty,
289 $websiteId = $this->stockConfiguration->getDefaultScopeId();
294 '(use_config_notify_stock_qty = 1 AND qty < ?)',
295 $this->_configNotifyStockQty
296 ) .
' OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty)';
297 $currentDbTime =
$connection->quoteInto(
'?', $this->dateTime->gmtDate());
298 $conditionalDate =
$connection->getCheckSql($condition, $currentDbTime,
'NULL');
300 $value = [
'low_stock_date' => new \Zend_Db_Expr($conditionalDate)];
303 ->where(
'type_id IN(?)', $this->_configTypeIds);
306 'website_id = %1$d' .
307 ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' .
308 ' AND product_id IN (%3$s)',
310 $this->_isConfigManageStock,
327 $connection = $collection->getSelect()->getConnection();
329 'invtr.use_config_notify_stock_qty > 0',
330 $this->_configNotifyStockQty,
331 'invtr.notify_stock_qty' 335 $connection->prepareSqlCondition(
'invtr.use_config_manage_stock', 1),
336 $connection->prepareSqlCondition($this->_isConfigManageStock, 1),
337 $connection->prepareSqlCondition(
'invtr.qty', [
'lt' => $qtyIf]),
340 $connection->prepareSqlCondition(
'invtr.use_config_manage_stock', 0),
341 $connection->prepareSqlCondition(
'invtr.manage_stock', 1)
346 foreach ($conditions as $k => $part) {
347 $where[$k] = join(
' ' . \
Magento\Framework\DB\Select::SQL_AND .
' ', $part);
351 'invtr.low_stock_date',
354 ') ' . \
Magento\Framework\DB\Select::SQL_OR .
' (',
359 [
'invtr' =>
'cataloginventory_stock_item'],
360 'product_id = entity_id',
const XML_PATH_BACKORDERS
updateSetOutOfStock($website=null)
updateSetInStock($website)
lockProductsStock(array $productIds, $websiteId)
_init($mainTable, $idFieldName)
const XML_PATH_NOTIFY_STOCK_QTY
updateLowStockDate($website)
const XML_PATH_MANAGE_STOCK
correctItemsQty(array $items, $websiteId, $operator)
addLowStockFilter(\Magento\Catalog\Model\ResourceModel\Product\Collection $collection, $fields)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, StockConfigurationInterface $stockConfiguration, StoreManagerInterface $storeManager, $connectionName=null)