/
NewAction.php
97 lines (84 loc) · 3.29 KB
/
NewAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Controller\Adminhtml\Product;
use Magento\Backend\App\Action;
use Magento\Catalog\Controller\Adminhtml\Product;
use Magento\Framework\App\ObjectManager;
class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product
{
/**
* @var Initialization\StockDataFilter
* @deprecated
*/
protected $stockFilter;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @var \Magento\Backend\Model\View\Result\ForwardFactory
*/
protected $resultForwardFactory;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;
/**
* @param Action\Context $context
* @param Builder $productBuilder
* @param Initialization\StockDataFilter $stockFilter
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Product\Builder $productBuilder,
Initialization\StockDataFilter $stockFilter,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager = null
) {
$this->stockFilter = $stockFilter;
parent::__construct($context, $productBuilder);
$this->resultPageFactory = $resultPageFactory;
$this->resultForwardFactory = $resultForwardFactory;
$this->storeManager = $storeManager ?: $this->_objectManager->get(
\Magento\Store\Model\StoreManagerInterface::class
);
}
/**
* Create new product page
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
if (!$this->getRequest()->getParam('set')) {
return $this->resultForwardFactory->create()->forward('noroute');
}
$product = $this->productBuilder->build($this->getRequest());
$store = $this->storeManager->getStore($product->getStoreId());
$this->storeManager->setCurrentStore($store->getCode());
$this->_eventManager->dispatch('catalog_product_new_action', ['product' => $product]);
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
if ($this->getRequest()->getParam('popup')) {
$resultPage->addHandle(['popup', 'catalog_product_' . $product->getTypeId()]);
} else {
$resultPage->addHandle(['catalog_product_' . $product->getTypeId()]);
$resultPage->setActiveMenu('Magento_Catalog::catalog_products');
$resultPage->getConfig()->getTitle()->prepend(__('Products'));
$resultPage->getConfig()->getTitle()->prepend(__('New Product'));
}
$block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');
if ($block) {
$block->setStoreId($product->getStoreId());
}
return $resultPage;
}
}