File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
app/code/Magento/Catalog/Model/Category/Product Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -49,4 +49,30 @@ public function getPositions(int $categoryId): array
49
49
50
50
return array_flip ($ connection ->fetchCol ($ select ));
51
51
}
52
+
53
+ /**
54
+ * Get category product minimum position
55
+ *
56
+ * @param int $categoryId
57
+ * @return int
58
+ */
59
+ public function getMinPosition (int $ categoryId ): int
60
+ {
61
+ $ connection = $ this ->getConnection ();
62
+
63
+ $ select = $ connection ->select ()->from (
64
+ ['cpe ' => $ this ->getTable ('catalog_product_entity ' )],
65
+ ['position ' => new \Zend_Db_Expr ('MIN(position) ' )]
66
+ )->joinLeft (
67
+ ['ccp ' => $ this ->getTable ('catalog_category_product ' )],
68
+ 'ccp.product_id=cpe.entity_id '
69
+ )->where (
70
+ 'ccp.category_id = ? ' ,
71
+ $ categoryId
72
+ )->order (
73
+ 'ccp.product_id ' . \Magento \Framework \DB \Select::SQL_DESC
74
+ );
75
+
76
+ return (int )$ connection ->fetchOne ($ select );
77
+ }
52
78
}
You can’t perform that action at this time.
0 commit comments