Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-inventory-shipping
Test
_files
products_virtual_rollback.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
use
Magento\Framework\Api\SearchCriteriaBuilder
;
9
use
Magento\Catalog\Api\ProductRepositoryInterface
;
10
use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory;
11
use
Magento\CatalogInventory\Api\StockStatusRepositoryInterface
;
12
use
Magento\Framework\Registry
;
13
use
Magento\TestFramework\Helper\Bootstrap
;
14
use
Magento\Catalog\Api\Data\ProductInterface
;
15
16
$objectManager
= Bootstrap::getObjectManager();
18
$productRepository
=
$objectManager
->create(ProductRepositoryInterface::class);
20
$registry
=
$objectManager
->get(Registry::class);
22
$stockStatusRepository
=
$objectManager
->create(StockStatusRepositoryInterface::class);
24
$stockStatusCriteriaFactory
=
$objectManager
->create(StockStatusCriteriaInterfaceFactory::class);
25
27
$searchCriteriaBuilder
= Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
28
$searchCriteria
=
$searchCriteriaBuilder
->addFilter(
29
ProductInterface::SKU,
30
[
'VIRT-1'
,
'VIRT-2'
,
'VIRT-3'
,
'VIRT-4'
],
31
'in'
32
)->create();
33
$products
=
$productRepository
->getList(
$searchCriteria
)->getItems();
34
39
if
(!empty(
$products
)) {
40
$currentArea =
$registry
->registry(
'isSecureArea'
);
41
$registry
->unregister(
'isSecureArea'
);
42
$registry
->register(
'isSecureArea'
,
true
);
43
44
foreach
(
$products
as
$product
) {
45
$criteria =
$stockStatusCriteriaFactory
->create();
46
$criteria->setProductsFilter(
$product
->getId());
47
48
$result
=
$stockStatusRepository
->getList($criteria);
49
if
(
$result
->getTotalCount()) {
50
$stockStatus = current(
$result
->getItems());
51
$stockStatusRepository
->delete($stockStatus);
52
}
53
54
$productRepository
->delete(
$product
);
55
}
56
57
$registry
->unregister(
'isSecureArea'
);
58
$registry
->register(
'isSecureArea'
, $currentArea);
59
}
$stockStatusCriteriaFactory
$stockStatusCriteriaFactory
Definition:
products_virtual_rollback.php:24
$result
$result
Definition:
product_configurable_not_available_rollback.php:26
$products
$products
Definition:
products_virtual_rollback.php:33
Magento\CatalogInventory\Api\StockStatusRepositoryInterface
Definition:
StockStatusRepositoryInterface.php:17
Magento\Framework\Api\SearchCriteriaBuilder
Definition:
SearchCriteriaBuilder.php:14
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
$productRepository
$productRepository
Definition:
products_virtual_rollback.php:18
Magento\Catalog\Api\ProductRepositoryInterface
Definition:
ProductRepositoryInterface.php:14
$searchCriteriaBuilder
$searchCriteriaBuilder
Definition:
products_virtual_rollback.php:27
$product
$product
Definition:
bundle_product_with_not_visible_children.php:22
$stockStatusRepository
$stockStatusRepository
Definition:
products_virtual_rollback.php:22
Magento\Framework\Registry
Definition:
Registry.php:18
Magento\Catalog\Api\Data\ProductInterface
Definition:
ProductInterface.php:14
$searchCriteria
$searchCriteria
Definition:
products_virtual_rollback.php:28
$registry
$registry
Definition:
products_virtual_rollback.php:20
$objectManager
$objectManager
Definition:
products_virtual_rollback.php:16