File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Model/Indexer/Product/Flat/Action
Test/Unit/Model/Indexer/Product/Flat/Action Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -85,10 +85,16 @@ public function execute($id = null)
85
85
$ ids = [$ id ];
86
86
$ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
87
87
88
+ $ storeIds = $ this ->getAssignedStoreIdsOfProduct ($ id );
89
+
88
90
$ stores = $ this ->_storeManager ->getStores ();
89
91
foreach ($ stores as $ store ) {
90
92
$ tableExists = $ this ->_isFlatTableExists ($ store ->getId ());
91
93
if ($ tableExists ) {
94
+ if (!in_array ($ store ->getId (), $ storeIds )) {
95
+ $ this ->flatItemEraser ->deleteProductsFromStore ($ id , $ store ->getId ());
96
+ continue ;
97
+ }
92
98
$ this ->flatItemEraser ->removeDeletedProducts ($ ids , $ store ->getId ());
93
99
$ this ->flatItemEraser ->removeDisabledProducts ($ ids , $ store ->getId ());
94
100
}
@@ -129,4 +135,23 @@ public function execute($id = null)
129
135
130
136
return $ this ;
131
137
}
138
+
139
+ /**
140
+ * Get list store id where the product is enable
141
+ *
142
+ * @param int $productId
143
+ * @return array
144
+ */
145
+ private function getAssignedStoreIdsOfProduct ($ productId )
146
+ {
147
+ $ select = $ this ->_connection ->select ();
148
+ $ select ->from (['e ' => $ this ->_productIndexerHelper ->getTable ('store ' )], ['e.store_id ' ])
149
+ ->where ('c.product_id = ' . $ productId )
150
+ ->joinLeft (
151
+ ['c ' => $ this ->_productIndexerHelper ->getTable ('catalog_product_website ' )],
152
+ 'e.website_id = c.website_id ' ,
153
+ []
154
+ );
155
+ return $ this ->_connection ->fetchCol ($ select );
156
+ }
132
157
}
Original file line number Diff line number Diff line change @@ -160,8 +160,24 @@ public function testExecuteWithExistingFlatTablesCreatesTables()
160
160
->willReturn ('store_flat_table ' );
161
161
$ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
162
162
->willReturn (true );
163
+ $ this ->connection ->expects ($ this ->any ())->method ('fetchCol ' )
164
+ ->willReturn (['store_id_1 ' ]);
163
165
$ this ->flatItemEraser ->expects ($ this ->once ())->method ('removeDeletedProducts ' );
164
166
$ this ->flatTableBuilder ->expects ($ this ->never ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
165
167
$ this ->model ->execute ('product_id_1 ' );
166
168
}
169
+
170
+ public function testExecuteWithExistingFlatTablesRemoveProductFromStore ()
171
+ {
172
+ $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getFlatTableName ' )
173
+ ->willReturn ('store_flat_table ' );
174
+ $ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
175
+ ->willReturn (true );
176
+ $ this ->connection ->expects ($ this ->any ())->method ('fetchCol ' )
177
+ ->willReturn ([1 ]);
178
+ $ this ->flatItemEraser ->expects ($ this ->once ())->method ('deleteProductsFromStore ' );
179
+ $ this ->flatItemEraser ->expects ($ this ->never ())->method ('removeDeletedProducts ' );
180
+ $ this ->flatTableBuilder ->expects ($ this ->never ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
181
+ $ this ->model ->execute ('product_id_1 ' );
182
+ }
167
183
}
You can’t perform that action at this time.
0 commit comments