Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Stock.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use Magento\ProductAlert\Model\StockFactory;
17 
21 class Stock extends \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Alerts\Stock
22 {
26  private $stockResolver;
27 
36  public function __construct(
37  Context $context,
38  Data $backendHelper,
39  StockFactory $stockFactory,
41  StockResolverInterface $stockResolver,
42  array $data = []
43  ) {
44  parent::__construct($context, $backendHelper, $stockFactory, $moduleManager, $data);
45 
46  $this->stockResolver = $stockResolver;
47  }
48 
52  protected function _prepareColumns()
53  {
54  parent::_prepareColumns();
55 
56  $this->addColumn('website_id', ['header' => __('Website'), 'index' => 'website_id']);
57  $this->addColumn('stock_name', ['header' => __('Stock'), 'index' => 'stock_name']);
58  }
59 
63  protected function _afterLoadCollection()
64  {
65  parent::_afterLoadCollection();
66 
67  foreach ($this->getCollection()->getItems() as $item) {
69  $website = $this->_storeManager->getWebsite($item->getWebsiteId());
70  $stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $website->getCode());
71  $item->setStockName($stock->getName());
72  }
73  }
74 }
__()
Definition: __.php:13
$stockFactory
Definition: stock.php:15
$stock
__construct(Context $context, Data $backendHelper, StockFactory $stockFactory, Manager $moduleManager, StockResolverInterface $stockResolver, array $data=[])
Definition: Stock.php:36