Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreventDeletingAssignedToSalesChannelsStockPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $assignedSalesChannelsForStock;
23 
27  public function __construct(
28  GetAssignedSalesChannelsForStockInterface $assignedSalesChannelsForStock
29  ) {
30  $this->assignedSalesChannelsForStock = $assignedSalesChannelsForStock;
31  }
32 
42  public function beforeDeleteById(StockRepositoryInterface $subject, int $stockId)
43  {
44  $assignSalesChannels = $this->assignedSalesChannelsForStock->execute($stockId);
45  if (count($assignSalesChannels)) {
46  throw new CouldNotDeleteException(__('Stock has at least one sale channel and could not be deleted.'));
47  }
48  }
49 }
__()
Definition: __.php:13