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-catalog
Plugin
InventoryApi
StockSourceLinksDelete
PreventDeleteDefaultStockLinksPlugin.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\InventoryCatalog\Plugin\InventoryApi\StockSourceLinksDelete
;
9
10
use
Magento\Framework\Exception\LocalizedException
;
11
use
Magento\InventoryApi\Api\StockSourceLinksDeleteInterface
;
12
use
Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface
;
13
use
Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface
;
14
18
class
PreventDeleteDefaultStockLinksPlugin
19
{
23
private
$defaultStockProvider;
24
28
private
$defaultSourceProvider;
29
34
public
function
__construct
(
35
DefaultStockProviderInterface
$defaultStockProvider,
36
DefaultSourceProviderInterface
$defaultSourceProvider
37
) {
38
$this->defaultStockProvider = $defaultStockProvider;
39
$this->defaultSourceProvider =
$defaultSourceProvider
;
40
}
41
51
public
function
beforeExecute
(
StockSourceLinksDeleteInterface
$subject, array
$links
)
52
{
53
foreach
(
$links
as
$link
) {
54
if
(
$link
->getStockId() === $this->defaultStockProvider->getId()
55
||
$link
->getSourceCode() === $this->defaultSourceProvider->getCode()
56
) {
57
throw
new
LocalizedException
(
__
(
'Can not delete link related to Default Source or Default Stock'
));
58
}
59
}
60
}
61
}
Magento\Framework\Exception\LocalizedException
Definition:
LocalizedException.php:17
Magento\InventoryCatalog\Plugin\InventoryApi\StockSourceLinksDelete\PreventDeleteDefaultStockLinksPlugin
Definition:
PreventDeleteDefaultStockLinksPlugin.php:18
Magento\InventoryCatalog\Plugin\InventoryApi\StockSourceLinksDelete\PreventDeleteDefaultStockLinksPlugin\__construct
__construct(DefaultStockProviderInterface $defaultStockProvider, DefaultSourceProviderInterface $defaultSourceProvider)
Definition:
PreventDeleteDefaultStockLinksPlugin.php:34
Magento\InventoryCatalog\Plugin\InventoryApi\StockSourceLinksDelete\PreventDeleteDefaultStockLinksPlugin\beforeExecute
beforeExecute(StockSourceLinksDeleteInterface $subject, array $links)
Definition:
PreventDeleteDefaultStockLinksPlugin.php:51
__
__()
Definition:
__.php:13
$defaultSourceProvider
$defaultSourceProvider
Definition:
source_items_on_default_source.php:22
$link
$link
Definition:
quote_with_downloadable_product.php:27
Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface
Definition:
DefaultSourceProviderInterface.php:15
$links
$links
Definition:
downloadable_product_with_files_and_sample_url.php:39
Magento\InventoryCatalog\Plugin\InventoryApi\StockSourceLinksDelete
Definition:
PreventDeleteDefaultStockLinksPlugin.php:8
Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface
Definition:
DefaultStockProviderInterface.php:15
Magento\InventoryApi\Api\StockSourceLinksDeleteInterface
Definition:
StockSourceLinksDeleteInterface.php:18