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_bundle_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);
26
$searchCriteriaBuilder
= Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
27
$searchCriteria
=
$searchCriteriaBuilder
->addFilter(
28
ProductInterface::SKU,
29
[
'SKU-BUNDLE-2'
,
'SKU-BUNDLE-3'
],
30
'in'
31
)->create();
32
$products
=
$productRepository
->getList(
$searchCriteria
)->getItems();
37
if
(!empty(
$products
)) {
38
$currentArea =
$registry
->registry(
'isSecureArea'
);
39
$registry
->unregister(
'isSecureArea'
);
40
$registry
->register(
'isSecureArea'
,
true
);
41
foreach
(
$products
as
$product
) {
42
$criteria =
$stockStatusCriteriaFactory
->create();
43
$criteria->setProductsFilter(
$product
->getId());
44
$result
=
$stockStatusRepository
->getList($criteria);
45
if
(
$result
->getTotalCount()) {
46
$stockStatus = current(
$result
->getItems());
47
$stockStatusRepository
->delete($stockStatus);
48
}
49
$productRepository
->delete(
$product
);
50
}
51
$registry
->unregister(
'isSecureArea'
);
52
$registry
->register(
'isSecureArea'
, $currentArea);
53
}
$result
$result
Definition:
product_configurable_not_available_rollback.php:26
Magento\CatalogInventory\Api\StockStatusRepositoryInterface
Definition:
StockStatusRepositoryInterface.php:17
Magento\Framework\Api\SearchCriteriaBuilder
Definition:
SearchCriteriaBuilder.php:14
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
$stockStatusRepository
$stockStatusRepository
Definition:
products_bundle_rollback.php:22
$products
$products
Definition:
products_bundle_rollback.php:32
Magento\Catalog\Api\ProductRepositoryInterface
Definition:
ProductRepositoryInterface.php:14
$objectManager
$objectManager
Definition:
products_bundle_rollback.php:16
$searchCriteriaBuilder
$searchCriteriaBuilder
Definition:
products_bundle_rollback.php:26
$productRepository
$productRepository
Definition:
products_bundle_rollback.php:18
$searchCriteria
$searchCriteria
Definition:
products_bundle_rollback.php:27
$product
$product
Definition:
bundle_product_with_not_visible_children.php:22
$registry
$registry
Definition:
products_bundle_rollback.php:20
Magento\Framework\Registry
Definition:
Registry.php:18
$stockStatusCriteriaFactory
$stockStatusCriteriaFactory
Definition:
products_bundle_rollback.php:24
Magento\Catalog\Api\Data\ProductInterface
Definition:
ProductInterface.php:14