10
10
use Magento \Framework \App \ResourceConnection as AppResource ;
11
11
use Magento \SalesSequence \Model \MetaFactory ;
12
12
use Magento \SalesSequence \Model \ResourceModel \Meta as ResourceMetadata ;
13
- use Magento \SalesSequence \Model \ResourceModel \Meta \Ids as ResourceMetadataIds ;
14
- use Magento \SalesSequence \Model \ResourceModel \Profile \Ids as ResourceProfileIds ;
15
13
use Magento \Store \Api \Data \StoreInterface ;
16
14
17
15
/**
@@ -24,16 +22,6 @@ class DeleteByStore
24
22
*/
25
23
private $ resourceMetadata ;
26
24
27
- /**
28
- * @var ResourceMetadataIds
29
- */
30
- private $ resourceMetadataIds ;
31
-
32
- /**
33
- * @var ResourceProfileIds
34
- */
35
- private $ resourceProfileIds ;
36
-
37
25
/**
38
26
* @var MetaFactory
39
27
*/
@@ -46,21 +34,15 @@ class DeleteByStore
46
34
47
35
/**
48
36
* @param ResourceMetadata $resourceMetadata
49
- * @param ResourceMetadataIds $resourceMetadataIds
50
- * @param ResourceProfileIds $resourceProfileIds
51
37
* @param MetaFactory $metaFactory
52
38
* @param AppResource $appResource
53
39
*/
54
40
public function __construct (
55
41
ResourceMetadata $ resourceMetadata ,
56
- ResourceMetadataIds $ resourceMetadataIds ,
57
- ResourceProfileIds $ resourceProfileIds ,
58
42
MetaFactory $ metaFactory ,
59
43
AppResource $ appResource
60
44
) {
61
45
$ this ->resourceMetadata = $ resourceMetadata ;
62
- $ this ->resourceMetadataIds = $ resourceMetadataIds ;
63
- $ this ->resourceProfileIds = $ resourceProfileIds ;
64
46
$ this ->metaFactory = $ metaFactory ;
65
47
$ this ->appResource = $ appResource ;
66
48
}
@@ -70,12 +52,12 @@ public function __construct(
70
52
*
71
53
* @param StoreInterface $store
72
54
* @return void
73
- * @throws \Magento\Framework\ Exception\LocalizedException
55
+ * @throws \Exception
74
56
*/
75
57
public function execute (StoreInterface $ store ): void
76
58
{
77
- $ metadataIds = $ this ->resourceMetadataIds -> getByStoreId ($ store ->getId ());
78
- $ profileIds = $ this ->resourceProfileIds -> getByMetadataIds ($ metadataIds );
59
+ $ metadataIds = $ this ->getMetadataIdsByStoreId ($ store ->getId ());
60
+ $ profileIds = $ this ->getProfileIdsByMetadataIds ($ metadataIds );
79
61
80
62
$ this ->appResource ->getConnection ()->delete (
81
63
$ this ->appResource ->getTableName ('sales_sequence_profile ' ),
@@ -95,4 +77,42 @@ public function execute(StoreInterface $store): void
95
77
$ this ->resourceMetadata ->delete ($ metadata );
96
78
}
97
79
}
80
+
81
+ /**
82
+ * Retrieves Metadata Ids by store id
83
+ *
84
+ * @param int $storeId
85
+ * @return int[]
86
+ */
87
+ private function getMetadataIdsByStoreId ($ storeId )
88
+ {
89
+ $ connection = $ this ->appResource ->getConnection ();
90
+ $ bind = ['store_id ' => $ storeId ];
91
+ $ select = $ connection ->select ()->from (
92
+ $ this ->appResource ->getTableName ('sales_sequence_meta ' ),
93
+ ['meta_id ' ]
94
+ )->where (
95
+ 'store_id = :store_id '
96
+ );
97
+
98
+ return $ connection ->fetchCol ($ select , $ bind );
99
+ }
100
+
101
+ /**
102
+ * Retrieves Profile Ids by metadata ids
103
+ *
104
+ * @param int[] $metadataIds
105
+ * @return int[]
106
+ */
107
+ private function getProfileIdsByMetadataIds (array $ metadataIds )
108
+ {
109
+ $ connection = $ this ->appResource ->getConnection ();
110
+ $ select = $ connection ->select ()
111
+ ->from (
112
+ $ this ->appResource ->getTableName ('sales_sequence_profile ' ),
113
+ ['profile_id ' ]
114
+ )->where ('meta_id IN (?) ' , $ metadataIds );
115
+
116
+ return $ connection ->fetchCol ($ select );
117
+ }
98
118
}
0 commit comments