Skip to content

Commit e9ab585

Browse files
author
Igor Melnikov
committed
MAGETWO-67871: Requesting autogenerated classes that are not in constructor cause fatal errors in production mode
- merge with remote branch, conflicts: app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php
2 parents 8887102 + 5d1590c commit e9ab585

File tree

104 files changed

+2967
-834
lines changed

Some content is hidden

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

104 files changed

+2967
-834
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ atlassian*
4848
/pub/media/favicon/*
4949
/pub/media/import/*
5050
!/pub/media/import/.htaccess
51+
/pub/media/logo/*
5152
/pub/media/theme/*
5253
/pub/media/theme_customization/*
5354
!/pub/media/theme_customization/.htaccess

app/code/Magento/Catalog/Block/Product/ProductList/Related.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ protected function _beforeToHtml()
116116
*/
117117
public function getItems()
118118
{
119+
/**
120+
* getIdentities() depends on _itemCollection populated, but it can be empty if the block is hidden
121+
* @see https://github.com/magento/magento2/issues/5897
122+
*/
123+
if (is_null($this->_itemCollection)) {
124+
$this->_prepareData();
125+
}
119126
return $this->_itemCollection;
120127
}
121128

app/code/Magento/Catalog/Block/Product/ProductList/Upsell.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ protected function _beforeToHtml()
135135
*/
136136
public function getItemCollection()
137137
{
138+
/**
139+
* getIdentities() depends on _itemCollection populated, but it can be empty if the block is hidden
140+
* @see https://github.com/magento/magento2/issues/5897
141+
*/
142+
if (is_null($this->_itemCollection)) {
143+
$this->_prepareData();
144+
}
138145
return $this->_itemCollection;
139146
}
140147

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class Helper
7373
*/
7474
private $dateTimeFilter;
7575

76+
/**
77+
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
78+
*/
79+
private $linkTypeProvider;
80+
7681
/**
7782
* Constructor
7883
*
@@ -85,6 +90,8 @@ class Helper
8590
* @param \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory|null $customOptionFactory
8691
* @param \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory|null $productLinkFactory
8792
* @param \Magento\Catalog\Api\ProductRepositoryInterface|null $productRepository
93+
* @param \Magento\Catalog\Model\Product\LinkTypeProvider|null $linkTypeProvider
94+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8895
*/
8996
public function __construct(
9097
\Magento\Framework\App\RequestInterface $request,
@@ -95,7 +102,8 @@ public function __construct(
95102
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
96103
\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory = null,
97104
\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinkFactory = null,
98-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository = null
105+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository = null,
106+
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
99107
) {
100108
$this->request = $request;
101109
$this->storeManager = $storeManager;
@@ -109,6 +117,8 @@ public function __construct(
109117
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
110118
$this->productRepository = $productRepository ?: \Magento\Framework\App\ObjectManager::getInstance()
111119
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
120+
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
121+
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
112122
}
113123

114124
/**
@@ -255,11 +265,17 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
255265

256266
$product = $this->productLinks->initializeLinks($product, $links);
257267
$productLinks = $product->getProductLinks();
258-
$linkTypes = [
259-
'related' => $product->getRelatedReadonly(),
260-
'upsell' => $product->getUpsellReadonly(),
261-
'crosssell' => $product->getCrosssellReadonly()
262-
];
268+
$linkTypes = [];
269+
270+
/** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkTypeObject */
271+
foreach ($this->linkTypeProvider->getItems() as $linkTypeObject) {
272+
$linkTypes[$linkTypeObject->getName()] = $product->getData($linkTypeObject->getName() . '_readonly');
273+
}
274+
275+
// skip linkTypes that were already processed on initializeLinks plugins
276+
foreach ($productLinks as $productLink) {
277+
unset($linkTypes[$productLink->getLinkType()]);
278+
}
263279

264280
foreach ($linkTypes as $linkType => $readonly) {
265281
if (isset($links[$linkType]) && !$readonly) {

app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Setup\ModuleContextInterface;
1212
use Magento\Framework\Setup\SchemaSetupInterface;
1313
use Magento\Framework\Setup\UpgradeSchemaInterface;
14+
use Magento\Framework\DB\Ddl\Table;
1415

1516
/**
1617
* Upgrade the Catalog module DB scheme
@@ -57,7 +58,13 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
5758
$setup->getConnection()->modifyColumn(
5859
$setup->getTable($table),
5960
'customer_group_id',
60-
['type' => 'integer', 'nullable' => false]
61+
[
62+
'type' => Table::TYPE_INTEGER,
63+
'nullable' => false,
64+
'unsigned' => true,
65+
'default' => '0',
66+
'comment' => 'Customer Group ID',
67+
]
6168
);
6269
}
6370
$this->recreateCatalogCategoryProductIndexTmpTable($setup);
@@ -80,6 +87,37 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
8087
'catalog_category_product_index_replica'
8188
);
8289
}
90+
91+
if (version_compare($context->getVersion(), '2.2.2', '<')) {
92+
$tables = [
93+
'catalog_product_entity_tier_price',
94+
'catalog_product_index_price_cfg_opt_agr_idx',
95+
'catalog_product_index_price_cfg_opt_agr_tmp',
96+
'catalog_product_index_price_cfg_opt_idx',
97+
'catalog_product_index_price_cfg_opt_tmp',
98+
'catalog_product_index_price_final_idx',
99+
'catalog_product_index_price_final_tmp',
100+
'catalog_product_index_price_idx',
101+
'catalog_product_index_price_opt_agr_idx',
102+
'catalog_product_index_price_opt_agr_tmp',
103+
'catalog_product_index_price_opt_idx',
104+
'catalog_product_index_price_opt_tmp',
105+
'catalog_product_index_price_tmp',
106+
];
107+
foreach ($tables as $table) {
108+
$setup->getConnection()->modifyColumn(
109+
$setup->getTable($table),
110+
'customer_group_id',
111+
[
112+
'type' => Table::TYPE_INTEGER,
113+
'nullable' => false,
114+
'unsigned' => true,
115+
'default' => '0',
116+
'comment' => 'Customer Group ID',
117+
]
118+
);
119+
}
120+
}
83121
$setup->endSetup();
84122
}
85123

0 commit comments

Comments
 (0)