Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Popup.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Catalog\Model\ProductFactory;
12 use Psr\Log\LoggerInterface;
14 
15 class Popup extends AbstractAction
16 {
22  const ADMIN_RESOURCE = 'Magento_Catalog::products';
23 
27  protected $registry;
28 
32  protected $factory;
33 
37  protected $logger;
38 
45  public function __construct(
46  Context $context,
48  ProductFactory $factory,
49  LoggerInterface $logger
50  ) {
51  $this->registry = $registry;
52  $this->factory = $factory;
53  $this->logger = $logger;
54  parent::__construct($context);
55  }
56 
62  public function execute()
63  {
64  $productId = (int)$this->getRequest()->getParam('id');
65 
67  $product = $this->factory->create();
68  $product->setStoreId($this->getRequest()->getParam('store', 0));
69 
70  $typeId = $this->getRequest()->getParam('type');
71  if (!$productId && $typeId) {
72  $product->setTypeId($typeId);
73  }
74  $product->setData('_edit_mode', true);
75 
76  if ($productId) {
77  try {
78  $product->load($productId);
79  } catch (\Exception $e) {
80  $product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
81  $this->logger->critical($e);
82  }
83  }
84 
85  $setId = (int)$this->getRequest()->getParam('set');
86  if ($setId) {
87  $product->setAttributeSetId($setId);
88  }
89  $this->registry->register('current_product', $product);
91  $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
92  return $resultLayout;
93  }
94 }
__construct(Context $context, Registry $registry, ProductFactory $factory, LoggerInterface $logger)
Definition: Popup.php:45