6 declare(strict_types=1);
28 use Psr\Log\LoggerInterface;
38 private $stockConfiguration;
43 private $getAllowedProductTypesForSourceItemManagement;
48 private $attributeRepository;
53 private $metadataPool;
58 private $filterStoreId;
96 $this->stockConfiguration = $stockConfiguration;
97 $this->getAllowedProductTypesForSourceItemManagement = $getAllowedProductTypesForSourceItemManagement;
98 $this->metadataPool = $metadataPool;
106 $this->
_init(SourceItemModel::class, SourceItemResourceModel::class);
110 $this->
addFilterToMap(
'product_name',
'product_entity_varchar.value');
127 if (
false === $this->_isFiltersRendered) {
128 $this->joinInventoryConfiguration();
129 $this->joinCatalogProduct();
131 $this->addProductTypeFilter();
132 $this->addNotifyStockQtyFilter();
133 $this->addEnabledSourceFilter();
134 $this->addSourceItemInStockFilter();
136 return parent::_renderFilters();
144 if (
false === $this->_isOrdersRendered) {
147 return parent::_renderOrders();
155 private function joinCatalogProduct()
157 $productEntityTable = $this->
getTable(
'catalog_product_entity');
158 $productEavVarcharTable = $this->
getTable(
'catalog_product_entity_varchar');
159 $nameAttribute = $this->attributeRepository->get(
'catalog_product',
'name');
161 $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
162 $linkField = $metadata->getLinkField();
165 [
'product_entity' => $productEntityTable],
171 [
'product_entity_varchar' => $productEavVarcharTable],
172 'product_entity_varchar.' . $linkField .
' = product_entity.' . $linkField .
' ' .
174 'AND product_entity_varchar.attribute_id = ' . (
int)
$nameAttribute->getAttributeId(),
178 if (
null !== $this->filterStoreId) {
180 [
'product_entity_varchar_store' => $productEavVarcharTable],
181 'product_entity_varchar_store.' . $linkField .
' = product_entity.' . $linkField .
' ' .
182 'AND product_entity_varchar_store.store_id = ' . (
int)$this->filterStoreId .
' ' .
183 'AND product_entity_varchar_store.attribute_id = ' . (
int)
$nameAttribute->getAttributeId(),
186 'product_entity_varchar_store.value',
187 'product_entity_varchar.value' 192 $this->
getSelect()->columns([
'product_name' =>
'product_entity_varchar.value']);
199 private function joinInventoryConfiguration()
201 $sourceItemConfigurationTable = $this->
getTable(
'inventory_low_stock_notification_configuration');
204 [
'notification_configuration' => $sourceItemConfigurationTable],
206 'main_table.%s = notification_configuration.%s AND main_table.%s = notification_configuration.%s',
219 private function addProductTypeFilter()
222 'product_entity.type_id',
223 $this->getAllowedProductTypesForSourceItemManagement->execute()
230 private function addNotifyStockQtyFilter()
232 $notifyStockExpression = $this->
getConnection()->getIfNullSql(
234 (
float)$this->stockConfiguration->getNotifyStockQty()
239 $notifyStockExpression
246 private function addEnabledSourceFilter()
251 'inventory_source.%s = 1 AND inventory_source.%s = main_table.%s',
263 private function addSourceItemInStockFilter()
addFilterToMap($filter, $alias, $group='fields')
const INVENTORY_NOTIFY_QTY
__construct(EntityFactoryInterface $entityFactory, LoggerInterface $logger, FetchStrategyInterface $fetchStrategy, ManagerInterface $eventManager, AttributeRepositoryInterface $attributeRepository, StockConfigurationInterface $stockConfiguration, GetAllowedProductTypesForSourceItemManagementInterface $getAllowedProductTypesForSourceItemManagement, MetadataPool $metadataPool, AdapterInterface $connection=null, AbstractDb $resource=null)
addFieldToFilter($attribute, $condition=null)
setOrder($field, $direction=self::SORT_ORDER_DESC)
addStoreFilter(int $storeId)
_init($model, $resourceModel)