1
+ <?php
2
+
3
+ require dirname (__FILE__ ) . '/davici/app/bootstrap.php ' ;
4
+ $ bootstrap = \Magento \Framework \App \Bootstrap::create (BP , $ _SERVER );
5
+
6
+ class Outslide extends \Magento \Framework \App \Http
7
+ implements \Magento \Framework \AppInterface {
8
+ public function launch ()
9
+ {
10
+ $ myClass = $ this ->_objectManager ->create ('DeleteProduct ' );
11
+ $ myClass ->deleteProducts ();
12
+ return $ this ->_response ;
13
+ }
14
+
15
+ }
16
+
17
+
18
+ class DeleteProduct{
19
+
20
+ protected $ _objectManager ;
21
+ protected $ _registry ;
22
+
23
+ /**
24
+ * @var \Magento\Catalog\Model\ProductRepository
25
+ */
26
+ protected $ productRepository ;
27
+
28
+ public function __construct (
29
+ \Magento \Framework \Registry $ registry ,
30
+ \Magento \Catalog \Model \ProductRepository $ productRepository
31
+ )
32
+ {
33
+ $ this ->_registry = $ registry ;
34
+ $ this ->productRepository = $ productRepository ;
35
+ $ this ->_objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
36
+ }
37
+
38
+ public function deleteProducts () {
39
+
40
+ $ this ->_registry ->register ("isSecureArea " , true );
41
+
42
+ $ productIds = ['400 ' , '401 ' ];
43
+
44
+ $ number = 0 ;
45
+ foreach ($ productIds as $ id ) {
46
+ $ this ->productRepository ->deleteById ($ id );
47
+ $ number ++;
48
+ }
49
+
50
+ if ($ number ) {
51
+ echo __ ('A total of %1 record(s) were deleted. ' , $ number );
52
+ }
53
+ }
54
+
55
+ }
56
+
57
+ /** @var \Magento\Framework\App\Http $app */
58
+ $ app = $ bootstrap ->createApplication ('Outslide ' );
59
+ $ bootstrap ->run ($ app );
0 commit comments