Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-inventory-catalog
Model
ResourceModel
AddStockDataToCollection.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\InventoryCatalog\Model\ResourceModel
;
9
10
use
Magento\Catalog\Model\ResourceModel\Product\Collection
;
11
use
Magento\InventoryIndexer\Indexer\IndexStructure
;
12
use
Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface
;
13
17
class
AddStockDataToCollection
18
{
22
private
$stockIndexTableNameResolver;
23
27
public
function
__construct
(
StockIndexTableNameResolverInterface
$stockIndexTableNameResolver)
28
{
29
$this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
30
}
31
38
public
function
execute
(
Collection
$collection
,
bool
$isFilterInStock,
int
$stockId)
39
{
40
$stockIndexTableName = $this->stockIndexTableNameResolver->execute($stockId);
41
42
$resource
=
$collection
->getResource();
43
$collection
->getSelect()->join(
44
[
'product'
=>
$resource
->getTable(
'catalog_product_entity'
)],
45
sprintf(
'product.entity_id = %s.entity_id'
,
Collection::MAIN_TABLE_ALIAS
),
46
[]
47
);
48
$collection
->getSelect()
49
->join(
50
[
'stock_status_index'
=> $stockIndexTableName],
51
'product.sku = stock_status_index.'
.
IndexStructure::SKU
,
52
[
IndexStructure::IS_SALABLE
]
53
);
54
55
if
($isFilterInStock) {
56
$collection
->getSelect()
57
->where(
'stock_status_index.'
.
IndexStructure::IS_SALABLE
.
' = ?'
, 1);
58
}
59
}
60
}
Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface
Definition:
StockIndexTableNameResolverInterface.php:15
Magento\Catalog\Model\ResourceModel\Product\Collection
Definition:
ProductLimitation.php:6
Magento\Catalog\Model\ResourceModel\Product\Collection\MAIN_TABLE_ALIAS
const MAIN_TABLE_ALIAS
Definition:
Collection.php:46
Magento\InventoryCatalog\Model\ResourceModel\AddStockDataToCollection\__construct
__construct(StockIndexTableNameResolverInterface $stockIndexTableNameResolver)
Definition:
AddStockDataToCollection.php:27
Magento\InventoryIndexer\Indexer\IndexStructure\IS_SALABLE
const IS_SALABLE
Definition:
IndexStructure.php:27
$resource
$resource
Definition:
bulk.php:12
Magento\InventoryIndexer\Indexer\IndexStructure\SKU
const SKU
Definition:
IndexStructure.php:25
Magento\InventoryIndexer\Indexer\IndexStructure
Definition:
IndexStructure.php:20
Magento\InventoryCatalog\Model\ResourceModel
Definition:
AddIsInStockFieldToCollection.php:8
Magento\Catalog\Model\ResourceModel\Product\Collection
Definition:
Collection.php:36
Magento\InventoryCatalog\Model\ResourceModel\AddStockDataToCollection
Definition:
AddStockDataToCollection.php:17
$collection
$collection
Definition:
catalog_category_with_apostrophe_rollback.php:17
Magento\InventoryCatalog\Model\ResourceModel\AddStockDataToCollection\execute
execute(Collection $collection, bool $isFilterInStock, int $stockId)
Definition:
AddStockDataToCollection.php:38