Skip to content

Commit cc95af3

Browse files
igrybkovle0n4eg
authored andcommitted
MAGETWO-69036: Lazy-loaders cause fatal errors in production mode on cloud
1 parent 409eef5 commit cc95af3

File tree

44 files changed

+1462
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1462
-631
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/AddAttributeToTemplate.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,22 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
8282
* @param \Magento\Backend\App\Action\Context $context
8383
* @param Builder $productBuilder
8484
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
85+
* @param AttributeGroupInterfaceFactory|null $attributeGroupFactory
8586
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8687
*/
8788
public function __construct(
8889
\Magento\Backend\App\Action\Context $context,
8990
\Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder,
90-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
91+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
92+
\Magento\Eav\Api\Data\AttributeGroupInterfaceFactory $attributeGroupFactory = null
9193
) {
9294
parent::__construct($context, $productBuilder);
9395
$this->resultJsonFactory = $resultJsonFactory;
96+
if (null === $attributeGroupFactory) {
97+
$attributeGroupFactory = \Magento\Framework\App\ObjectManager::getInstance()
98+
->get(\Magento\Eav\Api\Data\AttributeGroupInterfaceFactory::class);
99+
}
100+
$this->attributeGroupFactory = $attributeGroupFactory;
94101
}
95102

96103
/**
@@ -132,7 +139,7 @@ public function execute()
132139
$attributeGroup = reset($attributeGroupItems);
133140
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
134141
/** @var AttributeGroupInterface $attributeGroup */
135-
$attributeGroup = $this->getAttributeGroupFactory()->create();
142+
$attributeGroup = $this->attributeGroupFactory->create();
136143
}
137144

138145
$extensionAttributes = $attributeGroup->getExtensionAttributes()
@@ -228,18 +235,6 @@ private function getAttributeGroupRepository()
228235
return $this->attributeGroupRepository;
229236
}
230237

231-
/**
232-
* @return AttributeGroupInterfaceFactory
233-
*/
234-
private function getAttributeGroupFactory()
235-
{
236-
if (null === $this->attributeGroupFactory) {
237-
$this->attributeGroupFactory = \Magento\Framework\App\ObjectManager::getInstance()
238-
->get('Magento\Eav\Api\Data\AttributeGroupInterfaceFactory');
239-
}
240-
return $this->attributeGroupFactory;
241-
}
242-
243238
/**
244239
* @return SearchCriteriaBuilder
245240
*/

app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,24 @@ class Builder
4545
* @param Logger $logger
4646
* @param Registry $registry
4747
* @param WysiwygModel\Config $wysiwygConfig
48+
* @param StoreFactory|null $storeFactory
4849
*/
4950
public function __construct(
5051
ProductFactory $productFactory,
5152
Logger $logger,
5253
Registry $registry,
53-
WysiwygModel\Config $wysiwygConfig
54+
WysiwygModel\Config $wysiwygConfig,
55+
StoreFactory $storeFactory = null
5456
) {
5557
$this->productFactory = $productFactory;
5658
$this->logger = $logger;
5759
$this->registry = $registry;
5860
$this->wysiwygConfig = $wysiwygConfig;
61+
if (null === $storeFactory) {
62+
$storeFactory = \Magento\Framework\App\ObjectManager::getInstance()
63+
->get(StoreFactory::class);
64+
}
65+
$this->storeFactory = $storeFactory;
5966
}
6067

6168
/**
@@ -70,7 +77,7 @@ public function build(RequestInterface $request)
7077
/** @var $product \Magento\Catalog\Model\Product */
7178
$product = $this->productFactory->create();
7279
$product->setStoreId($request->getParam('store', 0));
73-
$store = $this->getStoreFactory()->create();
80+
$store = $this->storeFactory->create();
7481
$store->load($request->getParam('store', 0));
7582

7683
$typeId = $request->getParam('type');
@@ -99,16 +106,4 @@ public function build(RequestInterface $request)
99106
$this->wysiwygConfig->setStoreId($request->getParam('store'));
100107
return $product;
101108
}
102-
103-
/**
104-
* @return StoreFactory
105-
*/
106-
private function getStoreFactory()
107-
{
108-
if (null === $this->storeFactory) {
109-
$this->storeFactory = \Magento\Framework\App\ObjectManager::getInstance()
110-
->get('Magento\Store\Model\StoreFactory');
111-
}
112-
return $this->storeFactory;
113-
}
114109
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 57 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
*/
66
namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization;
77

8+
use Magento\Backend\Helper\Js;
89
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory as CustomOptionFactory;
910
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory as ProductLinkFactory;
1011
use Magento\Catalog\Api\ProductRepositoryInterface\Proxy as ProductRepository;
1112
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
1213
use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver;
14+
use Magento\Catalog\Model\Product\LinkTypeProvider;
1315
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\App\RequestInterface;
17+
use Magento\Framework\Stdlib\DateTime\Filter\Date as DateFilter;
18+
use Magento\Framework\Stdlib\DateTime\Filter\DateTime;
19+
use Magento\Store\Model\StoreManagerInterface;
1420

1521
/**
1622
* Class Helper
@@ -19,12 +25,12 @@
1925
class Helper
2026
{
2127
/**
22-
* @var \Magento\Framework\App\RequestInterface
28+
* @var RequestInterface
2329
*/
2430
protected $request;
2531

2632
/**
27-
* @var \Magento\Store\Model\StoreManagerInterface
33+
* @var StoreManagerInterface
2834
*/
2935
protected $storeManager;
3036

@@ -34,12 +40,12 @@ class Helper
3440
protected $stockFilter;
3541

3642
/**
37-
* @var \Magento\Backend\Helper\Js
43+
* @var Js
3844
*/
3945
protected $jsHelper;
4046

4147
/**
42-
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
48+
* @var Date
4349
*
4450
* @deprecated
4551
*/
@@ -71,42 +77,69 @@ class Helper
7177
private $linkResolver;
7278

7379
/**
74-
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
80+
* @var DateTime
7581
*/
7682
private $dateTimeFilter;
7783

7884
/**
79-
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
85+
* @var LinkTypeProvider
8086
*/
8187
private $linkTypeProvider;
8288

8389
/**
8490
* Helper constructor.
85-
* @param \Magento\Framework\App\RequestInterface $request
86-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
91+
* @param RequestInterface $request
92+
* @param StoreManagerInterface $storeManager
8793
* @param StockDataFilter $stockFilter
8894
* @param ProductLinks $productLinks
89-
* @param \Magento\Backend\Helper\Js $jsHelper
90-
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
91-
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
95+
* @param Js $jsHelper
96+
* @param DateFilter $dateFilter
97+
* @param LinkTypeProvider $linkTypeProvider
98+
* @param CustomOptionFactory $customOptionFactory
99+
* @param ProductLinkFactory $productLinkFactory
100+
* @param ProductRepository $productRepository
101+
* @param CustomOptionFactory $customOptionFactory
102+
* @param DateTime $dateTimeFilter
92103
*/
93104
public function __construct(
94-
\Magento\Framework\App\RequestInterface $request,
95-
\Magento\Store\Model\StoreManagerInterface $storeManager,
105+
RequestInterface $request,
106+
StoreManagerInterface $storeManager,
96107
StockDataFilter $stockFilter,
97-
\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks,
98-
\Magento\Backend\Helper\Js $jsHelper,
99-
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
100-
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
108+
ProductLinks $productLinks,
109+
Js $jsHelper,
110+
DateFilter $dateFilter,
111+
LinkTypeProvider $linkTypeProvider = null,
112+
CustomOptionFactory $customOptionFactory,
113+
ProductLinkFactory $productLinkFactory,
114+
ProductRepository $productRepository,
115+
DateTime $dateTimeFilter
101116
) {
117+
if (null === $linkTypeProvider) {
118+
$linkTypeProvider = ObjectManager::getInstance()->get(LinkTypeProvider::class);
119+
}
120+
if (null === $customOptionFactory) {
121+
$customOptionFactory = ObjectManager::getInstance()->get(CustomOptionFactory::class);
122+
}
123+
if (null === $productLinkFactory) {
124+
$productLinkFactory = ObjectManager::getInstance()->get(ProductLinkFactory::class);
125+
}
126+
if (null === $productRepository) {
127+
$productRepository = ObjectManager::getInstance()->get(ProductRepository::class);
128+
}
129+
if (null === $dateTimeFilter) {
130+
$dateTimeFilter = ObjectManager::getInstance()->get(DateTime::class);
131+
}
102132
$this->request = $request;
103133
$this->storeManager = $storeManager;
104134
$this->stockFilter = $stockFilter;
105135
$this->productLinks = $productLinks;
106136
$this->jsHelper = $jsHelper;
107137
$this->dateFilter = $dateFilter;
108-
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
109-
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
138+
$this->linkTypeProvider = $linkTypeProvider;
139+
$this->customOptionFactory = $customOptionFactory;
140+
$this->productLinkFactory = $productLinkFactory;
141+
$this->productRepository = $productRepository;
142+
$this->dateTimeFilter = $dateTimeFilter;
110143
}
111144

112145
/**
@@ -158,7 +191,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
158191
foreach ($attributes as $attrKey => $attribute) {
159192
if ($attribute->getBackend()->getType() == 'datetime') {
160193
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
161-
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
194+
$dateFieldFilters[$attrKey] = $this->dateTimeFilter;
162195
}
163196
}
164197
}
@@ -250,11 +283,12 @@ public function initialize(\Magento\Catalog\Model\Product $product)
250283
*
251284
* @param \Magento\Catalog\Model\Product $product
252285
* @return \Magento\Catalog\Model\Product
286+
* @throws \Magento\Framework\Exception\NoSuchEntityException
253287
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
254288
*/
255289
protected function setProductLinks(\Magento\Catalog\Model\Product $product)
256290
{
257-
$links = $this->getLinkResolver()->getLinks();
291+
$links = $this->linkResolver->getLinks();
258292

259293
$product->setProductLinks([]);
260294

@@ -279,8 +313,8 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
279313
continue;
280314
}
281315

282-
$linkProduct = $this->getProductRepository()->getById($linkData['id']);
283-
$link = $this->getProductLinkFactory()->create();
316+
$linkProduct = $this->productRepository->getById($linkData['id']);
317+
$link = $this->productLinkFactory->create();
284318
$link->setSku($product->getSku())
285319
->setLinkedProductSku($linkProduct->getSku())
286320
->setLinkType($linkType)
@@ -387,71 +421,4 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
387421

388422
return $option;
389423
}
390-
391-
/**
392-
* @return CustomOptionFactory
393-
*/
394-
private function getCustomOptionFactory()
395-
{
396-
if (null === $this->customOptionFactory) {
397-
$this->customOptionFactory = \Magento\Framework\App\ObjectManager::getInstance()
398-
->get(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
399-
}
400-
401-
return $this->customOptionFactory;
402-
}
403-
404-
/**
405-
* @return ProductLinkFactory
406-
*/
407-
private function getProductLinkFactory()
408-
{
409-
if (null === $this->productLinkFactory) {
410-
$this->productLinkFactory = \Magento\Framework\App\ObjectManager::getInstance()
411-
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
412-
}
413-
414-
return $this->productLinkFactory;
415-
}
416-
417-
/**
418-
* @return ProductRepository
419-
*/
420-
private function getProductRepository()
421-
{
422-
if (null === $this->productRepository) {
423-
$this->productRepository = \Magento\Framework\App\ObjectManager::getInstance()
424-
->get(\Magento\Catalog\Api\ProductRepositoryInterface\Proxy::class);
425-
}
426-
427-
return $this->productRepository;
428-
}
429-
430-
/**
431-
* @deprecated
432-
* @return LinkResolver
433-
*/
434-
private function getLinkResolver()
435-
{
436-
if (!is_object($this->linkResolver)) {
437-
$this->linkResolver = ObjectManager::getInstance()->get(LinkResolver::class);
438-
}
439-
440-
return $this->linkResolver;
441-
}
442-
443-
/**
444-
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
445-
*
446-
* @deprecated
447-
*/
448-
private function getDateTimeFilter()
449-
{
450-
if ($this->dateTimeFilter === null) {
451-
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
452-
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
453-
}
454-
455-
return $this->dateTimeFilter;
456-
}
457424
}

0 commit comments

Comments
 (0)