Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreventDeleteDefaultStockLinksPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
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 }
__()
Definition: __.php:13