Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LoadSalesChannelsOnGetPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use Psr\Log\LoggerInterface;
15 
20 {
24  private $getAssignedSalesChannelsForStock;
25 
29  private $logger;
30 
35  public function __construct(
36  GetAssignedSalesChannelsForStockInterface $getAssignedSalesChannelsForStock,
37  LoggerInterface $logger
38  ) {
39  $this->getAssignedSalesChannelsForStock = $getAssignedSalesChannelsForStock;
40  $this->logger = $logger;
41  }
42 
53  {
54  try {
55  $salesChannels = $this->getAssignedSalesChannelsForStock->execute((int)$stock->getStockId());
56 
57  $extensionAttributes = $stock->getExtensionAttributes();
58  $extensionAttributes->setSalesChannels($salesChannels);
59  $stock->setExtensionAttributes($extensionAttributes);
60  return $stock;
61  } catch (\Exception $e) {
62  $this->logger->error($e->getMessage());
63  throw new StateException(__('Could not load Sales Channels for Stock'), $e);
64  }
65  }
66 }
__()
Definition: __.php:13
$logger
$extensionAttributes
Definition: payment.php:22
__construct(GetAssignedSalesChannelsForStockInterface $getAssignedSalesChannelsForStock, LoggerInterface $logger)
$stock