52 private $queryProcessorComposite;
83 $this->_scopeConfig = $scopeConfig;
94 $this->
_init(
'cataloginventory_stock_status',
'product_id');
105 $this->tableStrategy->setUseIdxTable(
true);
126 $this->tableStrategy->setUseIdxTable(
false);
143 return $this->actionType;
155 $this->actionType =
$type;
167 $this->_typeId = $typeId;
179 if ($this->_typeId ===
null) {
180 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Undefined product type'));
193 $this->_isComposite = (bool) $flag;
215 return $this->_scopeConfig->isSetFlag(
232 $qtyExpr =
$connection->getCheckSql(
'cisi.qty > 0',
'cisi.qty', 0);
234 $linkField = $metadata->getLinkField();
237 [
'e' => $this->
getTable(
'catalog_product_entity')],
241 [
'cis' => $this->
getTable(
'cataloginventory_stock')],
243 [
'website_id',
'stock_id']
245 [
'cisi' => $this->
getTable(
'cataloginventory_stock_item')],
246 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id',
249 [
'mcpei' => $this->
getTable(
'catalog_product_entity_int')],
250 'e.' . $linkField .
' = mcpei.' . $linkField
251 .
' AND mcpei.attribute_id = ' . $this->
_getAttribute(
'status')->getId()
252 .
' AND mcpei.value = ' . ProductStatus::STATUS_ENABLED,
257 'cis.website_id = ?',
259 )->where(
'e.type_id = ?', $this->
getTypeId())
260 ->group([
'e.entity_id',
'cis.website_id',
'cis.stock_id']);
263 if ($entityIds !==
null) {
264 $select->where(
'e.entity_id IN(?)', $entityIds);
280 $select = $this->getQueryProcessorComposite()->processQuery(
$select, $entityIds);
297 $select = $this->getQueryProcessorComposite()->processQuery(
$select, $entityIds,
true);
302 while (
$row =
$query->fetch(\PDO::FETCH_ASSOC)) {
305 'product_id' => (int)
$row[
'entity_id'],
306 'website_id' => (
int)
$row[
'website_id'],
308 'qty' => (double)
$row[
'qty'],
309 'stock_status' => (
int)
$row[
'status'],
311 if (
$i % 1000 == 0) {
317 $this->deleteOldRecords($entityIds);
331 private function deleteOldRecords(array $ids)
333 if (count($ids) !== 0) {
365 return $this->tableStrategy->getTableName(
'cataloginventory_stock_status');
376 $isInStockExpression = $isAggregate ?
'MAX(cisi.is_in_stock)' :
'cisi.is_in_stock';
379 'cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0',
385 'cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1',
386 $isInStockExpression,
401 if ($this->stockConfiguration ===
null) {
403 ->get(\
Magento\CatalogInventory\Api\StockConfigurationInterface::class);
411 private function getQueryProcessorComposite()
413 if (
null === $this->queryProcessorComposite) {
417 return $this->queryProcessorComposite;
_prepareIndexTable($entityIds=null)
getStatusExpression(AdapterInterface $connection, $isAggregate=false)
_init($mainTable, $idFieldName)
const XML_PATH_MANAGE_STOCK
_getStockStatusSelect($entityIds=null, $usePrimaryTable=false)
reindexEntity($entityIds)
_getAttribute($attributeCode)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $connectionName=null)