Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetUnassignedSalesChannelsForStock.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
18 {
22  private $getAssignedSalesChannelsForStock;
23 
27  public function __construct(
28  GetAssignedSalesChannelsForStockInterface $getAssignedSalesChannelsForStock
29  ) {
30  $this->getAssignedSalesChannelsForStock = $getAssignedSalesChannelsForStock;
31  }
32 
39  public function execute(StockInterface $stock): array
40  {
41  $newWebsiteCodes = $result = [];
42  $assignedSalesChannels = $this->getAssignedSalesChannelsForStock->execute((int)$stock->getStockId());
43  $extensionAttributes = $stock->getExtensionAttributes();
44  $newSalesChannels = $extensionAttributes->getSalesChannels() ?: [];
45 
46  foreach ($newSalesChannels as $salesChannel) {
47  if ($salesChannel->getType() === SalesChannel::TYPE_WEBSITE) {
48  $newWebsiteCodes[] = $salesChannel->getCode();
49  }
50  }
51 
52  foreach ($assignedSalesChannels as $salesChannel) {
53  if ($salesChannel->getType() === SalesChannel::TYPE_WEBSITE
54  && !in_array($salesChannel->getCode(), $newWebsiteCodes, true)
55  ) {
56  $result[] = $salesChannel;
57  }
58  }
59 
60  return $result;
61  }
62 }
__construct(GetAssignedSalesChannelsForStockInterface $getAssignedSalesChannelsForStock)
$extensionAttributes
Definition: payment.php:22
$stock