@@ -375,22 +375,42 @@ public function getAvailableInCategories($object)
375
375
// fetching all parent IDs, including those are higher on the tree
376
376
$ entityId = (int )$ object ->getEntityId ();
377
377
if (!isset ($ this ->availableCategoryIdsCache [$ entityId ])) {
378
- $ this ->availableCategoryIdsCache [$ entityId ] = $ this ->getConnection ()->fetchCol (
379
- $ this ->getConnection ()->select ()->distinct ()->from (
380
- $ this ->tableMaintainer ->getMainTable ($ object ->getStoreId ()),
381
- ['category_id ' ]
382
- )->where (
383
- 'product_id = ? AND is_parent = 1 ' ,
384
- $ entityId
385
- )->where (
386
- 'visibility != ? ' ,
387
- \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE
388
- )
378
+ foreach ($ this ->_storeManager ->getStores () as $ store ) {
379
+ $ unionTables [] = $ this ->getAvailableInCategoriesSelect (
380
+ $ entityId ,
381
+ $ this ->tableMaintainer ->getMainTable ($ store ->getId ())
382
+ );
383
+ }
384
+ $ unionSelect = new \Magento \Framework \DB \Sql \UnionExpression (
385
+ $ unionTables ,
386
+ \Magento \Framework \DB \Select::SQL_UNION_ALL
389
387
);
388
+ $ this ->availableCategoryIdsCache [$ entityId ] = array_unique ($ this ->getConnection ()->fetchCol ($ unionSelect ));
390
389
}
391
390
return $ this ->availableCategoryIdsCache [$ entityId ];
392
391
}
393
392
393
+ /**
394
+ * Returns DB select for available categories.
395
+ *
396
+ * @param int $entityId
397
+ * @param string $tableName
398
+ * @return \Magento\Framework\DB\Select
399
+ */
400
+ private function getAvailableInCategoriesSelect ($ entityId , $ tableName )
401
+ {
402
+ return $ this ->getConnection ()->select ()->distinct ()->from (
403
+ $ tableName ,
404
+ ['category_id ' ]
405
+ )->where (
406
+ 'product_id = ? AND is_parent = 1 ' ,
407
+ $ entityId
408
+ )->where (
409
+ 'visibility != ? ' ,
410
+ \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE
411
+ );
412
+ }
413
+
394
414
/**
395
415
* Get default attribute source model
396
416
*
0 commit comments