File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Catalog/Ui/DataProvider/Product Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -25,4 +25,58 @@ protected function _productLimitationJoinPrice()
25
25
$ this ->_productLimitationFilters ->setUsePriceIndex (false );
26
26
return $ this ->_productLimitationPrice (true );
27
27
}
28
+
29
+ /**
30
+ * Return approximately amount if too much entities.
31
+ *
32
+ * @return int|mixed
33
+ */
34
+ public function getSize ()
35
+ {
36
+ $ sql = $ this ->getSelectCountSql ();
37
+ $ possibleCount = $ this ->analyzeCount ($ sql );
38
+
39
+ if ($ possibleCount > 20000 ) {
40
+ return $ possibleCount ;
41
+ }
42
+
43
+ return parent ::getSize ();
44
+ }
45
+
46
+ /**
47
+ * Analyze amount of entities in DB.
48
+ *
49
+ * @param $sql
50
+ * @return int|mixed
51
+ * @throws \Zend_Db_Statement_Exception
52
+ */
53
+ private function analyzeCount ($ sql )
54
+ {
55
+ $ results = $ this ->getConnection ()->query ('EXPLAIN ' . $ sql )->fetchAll ();
56
+ $ alias = $ this ->getMainTableAlias ();
57
+
58
+ foreach ($ results as $ result ) {
59
+ if ($ result ['table ' ] == $ alias ) {
60
+ return $ result ['rows ' ];
61
+ }
62
+ }
63
+
64
+ return 0 ;
65
+ }
66
+
67
+ /**
68
+ * Identify main table alias or its name if alias is not defined.
69
+ *
70
+ * @return string
71
+ * @throws \LogicException
72
+ */
73
+ private function getMainTableAlias ()
74
+ {
75
+ foreach ($ this ->getSelect ()->getPart (\Magento \Framework \DB \Select::FROM ) as $ tableAlias => $ tableMetadata ) {
76
+ if ($ tableMetadata ['joinType ' ] == 'from ' ) {
77
+ return $ tableAlias ;
78
+ }
79
+ }
80
+ throw new \LogicException ("Main table cannot be identified. " );
81
+ }
28
82
}
Original file line number Diff line number Diff line change 48
48
</argument >
49
49
</arguments >
50
50
</type >
51
+ <type name =" Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider\ProductCollection" >
52
+ <arguments >
53
+ <argument name =" collectionFactory" xsi : type =" object" >\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument >
54
+ </arguments >
55
+ </type >
51
56
</config >
You can’t perform that action at this time.
0 commit comments