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