Skip to content

Commit f4e5311

Browse files
authored
🔃 [Magento Community Engineering] Community Contributions
Accepted Community Pull Requests: - #26355: Performance: Getting rid of `array_merge` in loop (by @lbajsarowicz) - #26000: magento/magento2#: Remove unused �Default Email Domain� option and related to it code (by @atwixfirster) - #26296: Add Visual Code catalog generator (by @manuelcanepa) - #25966: [Fixed Radio alignment issue] (by @hitesh-wagento) - #24460: Allow construction of products with custom_attributes in $data (by @Vinai) - #25764: Cleanup, refactor and cover with tests section-config module (by @krzksz) - #25875: Prevent endless loop when duplicating product (by @JeroenVanLeusden) Fixed GitHub Issues: - #25962: Radio alignment issue (reported by @hitesh-wagento) has been fixed in #25966 by @hitesh-wagento in 2.4-develop branch Related commits: 1. e9b92e5 2. 6d7f34e 3. a505a16 4. 75c2fb5 5. b8480b8 - #17125: x-magento-init initialisation not bound to happen in the right order. (reported by @kshaa) has been fixed in #25764 by @krzksz in 2.4-develop branch Related commits: 1. 976302d 2. 5be754b - #9466: Duplicating product copies product images couple of hundred times (reported by @qbixx) has been fixed in #25875 by @JeroenVanLeusden in 2.4-develop branch Related commits: 1. 8e2959d 2. a027e87 3. 64cb774
2 parents 4b78d9a + 10a6705 commit f4e5311

File tree

57 files changed

+1171
-645
lines changed

Some content is hidden

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

57 files changed

+1171
-645
lines changed

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66

77
namespace Magento\Catalog\Block\Product\ProductList;
88

9+
use Magento\Catalog\Block\Product\AbstractProduct;
10+
use Magento\Catalog\Block\Product\Context;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Visibility as ProductVisibility;
913
use Magento\Catalog\Model\ResourceModel\Product\Collection;
14+
use Magento\Checkout\Model\ResourceModel\Cart as CartResourceModel;
15+
use Magento\Checkout\Model\Session as CheckoutSession;
16+
use Magento\Framework\DataObject\IdentityInterface;
17+
use Magento\Framework\Module\Manager;
1018
use Magento\Framework\View\Element\AbstractBlock;
1119

1220
/**
@@ -16,8 +24,7 @@
1624
* @SuppressWarnings(PHPMD.LongVariable)
1725
* @since 100.0.2
1826
*/
19-
class Related extends \Magento\Catalog\Block\Product\AbstractProduct implements
20-
\Magento\Framework\DataObject\IdentityInterface
27+
class Related extends AbstractProduct implements IdentityInterface
2128
{
2229
/**
2330
* @var Collection
@@ -27,53 +34,50 @@ class Related extends \Magento\Catalog\Block\Product\AbstractProduct implements
2734
/**
2835
* Checkout session
2936
*
30-
* @var \Magento\Checkout\Model\Session
37+
* @var CheckoutSession
3138
*/
3239
protected $_checkoutSession;
3340

3441
/**
3542
* Catalog product visibility
3643
*
37-
* @var \Magento\Catalog\Model\Product\Visibility
44+
* @var ProductVisibility
3845
*/
3946
protected $_catalogProductVisibility;
4047

4148
/**
4249
* Checkout cart
4350
*
44-
* @var \Magento\Checkout\Model\ResourceModel\Cart
51+
* @var CartResourceModel
4552
*/
4653
protected $_checkoutCart;
4754

4855
/**
49-
* @var \Magento\Framework\Module\Manager
56+
* @var Manager
5057
*/
5158
protected $moduleManager;
5259

5360
/**
54-
* @param \Magento\Catalog\Block\Product\Context $context
55-
* @param \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart
56-
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
57-
* @param \Magento\Checkout\Model\Session $checkoutSession
58-
* @param \Magento\Framework\Module\Manager $moduleManager
61+
* @param Context $context
62+
* @param CartResourceModel $checkoutCart
63+
* @param ProductVisibility $catalogProductVisibility
64+
* @param CheckoutSession $checkoutSession
65+
* @param Manager $moduleManager
5966
* @param array $data
6067
*/
6168
public function __construct(
62-
\Magento\Catalog\Block\Product\Context $context,
63-
\Magento\Checkout\Model\ResourceModel\Cart $checkoutCart,
64-
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
65-
\Magento\Checkout\Model\Session $checkoutSession,
66-
\Magento\Framework\Module\Manager $moduleManager,
69+
Context $context,
70+
CartResourceModel $checkoutCart,
71+
ProductVisibility $catalogProductVisibility,
72+
CheckoutSession $checkoutSession,
73+
Manager $moduleManager,
6774
array $data = []
6875
) {
6976
$this->_checkoutCart = $checkoutCart;
7077
$this->_catalogProductVisibility = $catalogProductVisibility;
7178
$this->_checkoutSession = $checkoutSession;
7279
$this->moduleManager = $moduleManager;
73-
parent::__construct(
74-
$context,
75-
$data
76-
);
80+
parent::__construct($context, $data);
7781
}
7882

7983
/**
@@ -84,7 +88,7 @@ public function __construct(
8488
protected function _prepareData()
8589
{
8690
$product = $this->getProduct();
87-
/* @var $product \Magento\Catalog\Model\Product */
91+
/* @var $product Product */
8892

8993
$this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect(
9094
'required_options'
@@ -139,12 +143,11 @@ public function getItems()
139143
*/
140144
public function getIdentities()
141145
{
142-
$identities = [];
146+
$identities = [[]];
143147
foreach ($this->getItems() as $item) {
144-
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
145-
$identities = array_merge($identities, $item->getIdentities());
148+
$identities[] = $item->getIdentities();
146149
}
147-
return $identities;
150+
return array_merge(...$identities);
148151
}
149152

150153
/**

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

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66

77
namespace Magento\Catalog\Block\Product\ProductList;
88

9+
use Magento\Catalog\Block\Product\AbstractProduct;
10+
use Magento\Catalog\Block\Product\Context;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Visibility as ProductVisibility;
913
use Magento\Catalog\Model\ResourceModel\Product\Collection;
14+
use Magento\Checkout\Model\ResourceModel\Cart as CartResourceModel;
15+
use Magento\Checkout\Model\Session as CheckoutSession;
16+
use Magento\Framework\DataObject;
17+
use Magento\Framework\DataObject\IdentityInterface;
18+
use Magento\Framework\Module\Manager;
1019

1120
/**
1221
* Catalog product upsell items block
@@ -15,16 +24,15 @@
1524
* @SuppressWarnings(PHPMD.LongVariable)
1625
* @since 100.0.2
1726
*/
18-
class Upsell extends \Magento\Catalog\Block\Product\AbstractProduct implements
19-
\Magento\Framework\DataObject\IdentityInterface
27+
class Upsell extends AbstractProduct implements IdentityInterface
2028
{
2129
/**
2230
* @var int
2331
*/
2432
protected $_columnCount = 4;
2533

2634
/**
27-
* @var \Magento\Framework\DataObject[]
35+
* @var DataObject[]
2836
*/
2937
protected $_items;
3038

@@ -41,53 +49,50 @@ class Upsell extends \Magento\Catalog\Block\Product\AbstractProduct implements
4149
/**
4250
* Checkout session
4351
*
44-
* @var \Magento\Checkout\Model\Session
52+
* @var CheckoutSession
4553
*/
4654
protected $_checkoutSession;
4755

4856
/**
4957
* Catalog product visibility
5058
*
51-
* @var \Magento\Catalog\Model\Product\Visibility
59+
* @var ProductVisibility
5260
*/
5361
protected $_catalogProductVisibility;
5462

5563
/**
5664
* Checkout cart
5765
*
58-
* @var \Magento\Checkout\Model\ResourceModel\Cart
66+
* @var CartResourceModel
5967
*/
6068
protected $_checkoutCart;
6169

6270
/**
63-
* @var \Magento\Framework\Module\Manager
71+
* @var Manager
6472
*/
6573
protected $moduleManager;
6674

6775
/**
68-
* @param \Magento\Catalog\Block\Product\Context $context
69-
* @param \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart
70-
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
71-
* @param \Magento\Checkout\Model\Session $checkoutSession
72-
* @param \Magento\Framework\Module\Manager $moduleManager
76+
* @param Context $context
77+
* @param CartResourceModel $checkoutCart
78+
* @param ProductVisibility $catalogProductVisibility
79+
* @param CheckoutSession $checkoutSession
80+
* @param Manager $moduleManager
7381
* @param array $data
7482
*/
7583
public function __construct(
76-
\Magento\Catalog\Block\Product\Context $context,
77-
\Magento\Checkout\Model\ResourceModel\Cart $checkoutCart,
78-
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
79-
\Magento\Checkout\Model\Session $checkoutSession,
80-
\Magento\Framework\Module\Manager $moduleManager,
84+
Context $context,
85+
CartResourceModel $checkoutCart,
86+
ProductVisibility $catalogProductVisibility,
87+
CheckoutSession $checkoutSession,
88+
Manager $moduleManager,
8189
array $data = []
8290
) {
8391
$this->_checkoutCart = $checkoutCart;
8492
$this->_catalogProductVisibility = $catalogProductVisibility;
8593
$this->_checkoutSession = $checkoutSession;
8694
$this->moduleManager = $moduleManager;
87-
parent::__construct(
88-
$context,
89-
$data
90-
);
95+
parent::__construct($context, $data);
9196
}
9297

9398
/**
@@ -98,7 +103,7 @@ public function __construct(
98103
protected function _prepareData()
99104
{
100105
$product = $this->getProduct();
101-
/* @var $product \Magento\Catalog\Model\Product */
106+
/* @var $product Product */
102107
$this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter();
103108
if ($this->moduleManager->isEnabled('Magento_Checkout')) {
104109
$this->_addProductAttributesAndPrices($this->_itemCollection);
@@ -181,8 +186,8 @@ public function getRowCount()
181186
*/
182187
public function setColumnCount($columns)
183188
{
184-
if ((int) $columns > 0) {
185-
$this->_columnCount = (int) $columns;
189+
if ((int)$columns > 0) {
190+
$this->_columnCount = (int)$columns;
186191
}
187192
return $this;
188193
}
@@ -231,8 +236,8 @@ public function getIterableItem()
231236
*/
232237
public function setItemLimit($type, $limit)
233238
{
234-
if ((int) $limit > 0) {
235-
$this->_itemLimits[$type] = (int) $limit;
239+
if ((int)$limit > 0) {
240+
$this->_itemLimits[$type] = (int)$limit;
236241
}
237242
return $this;
238243
}
@@ -250,9 +255,9 @@ public function getItemLimit($type = '')
250255
}
251256
if (isset($this->_itemLimits[$type])) {
252257
return $this->_itemLimits[$type];
253-
} else {
254-
return 0;
255258
}
259+
260+
return 0;
256261
}
257262

258263
/**
@@ -262,11 +267,10 @@ public function getItemLimit($type = '')
262267
*/
263268
public function getIdentities()
264269
{
265-
$identities = [];
266-
foreach ($this->getItems() as $item) {
267-
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
268-
$identities = array_merge($identities, $item->getIdentities());
269-
}
270-
return $identities;
270+
$identities = array_map(function (DataObject $item) {
271+
return $item->getIdentities();
272+
}, $this->getItems()) ?: [[]];
273+
274+
return array_merge(...$identities);
271275
}
272276
}

app/code/Magento/Catalog/Model/Product.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ public function __construct(
460460
$this->mediaGalleryEntryConverterPool = $mediaGalleryEntryConverterPool;
461461
$this->dataObjectHelper = $dataObjectHelper;
462462
$this->joinProcessor = $joinProcessor;
463+
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
464+
$this->filterCustomAttribute = $filterCustomAttribute
465+
?? ObjectManager::getInstance()->get(FilterProductCustomAttribute::class);
463466
parent::__construct(
464467
$context,
465468
$registry,
@@ -470,9 +473,6 @@ public function __construct(
470473
$resourceCollection,
471474
$data
472475
);
473-
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
474-
$this->filterCustomAttribute = $filterCustomAttribute
475-
?? ObjectManager::getInstance()->get(FilterProductCustomAttribute::class);
476476
}
477477

478478
/**
@@ -2160,6 +2160,7 @@ public function reset()
21602160
*/
21612161
public function getCacheIdTags()
21622162
{
2163+
// phpstan:ignore
21632164
$tags = parent::getCacheIdTags();
21642165
$affectedCategoryIds = $this->getAffectedCategoryIds();
21652166
if (!$affectedCategoryIds) {
@@ -2340,6 +2341,7 @@ public function isDisabled()
23402341
public function getImage()
23412342
{
23422343
$this->getTypeInstance()->setImageFromChildProduct($this);
2344+
// phpstan:ignore
23432345
return parent::getImage();
23442346
}
23452347

@@ -2403,6 +2405,7 @@ public function reloadPriceInfo()
24032405
}
24042406
}
24052407

2408+
// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
24062409
/**
24072410
* Return Data Object data in array format.
24082411
*
@@ -2411,6 +2414,7 @@ public function reloadPriceInfo()
24112414
*/
24122415
public function __toArray()
24132416
{
2417+
// phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
24142418
$data = $this->_data;
24152419
$hasToArray = function ($model) {
24162420
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);

0 commit comments

Comments
 (0)