Skip to content

Commit 8c9189f

Browse files
authored
Merge branch '2.4-develop' into bugfix/rest-api-pagination
2 parents 6c171ce + 0d3defe commit 8c9189f

File tree

83 files changed

+4136
-520
lines changed

Some content is hidden

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

83 files changed

+4136
-520
lines changed

.htaccess

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,6 @@
3737

3838
DirectoryIndex index.php
3939

40-
<IfModule mod_php5.c>
41-
############################################
42-
## adjust memory limit
43-
44-
php_value memory_limit 756M
45-
php_value max_execution_time 18000
46-
47-
############################################
48-
## disable automatic session start
49-
## before autoload was initialized
50-
51-
php_flag session.auto_start off
52-
53-
############################################
54-
## enable resulting html compression
55-
56-
#php_flag zlib.output_compression on
57-
58-
###########################################
59-
## disable user agent verification to not break multiple image upload
60-
61-
php_flag suhosin.session.cryptua off
62-
</IfModule>
6340
<IfModule mod_php7.c>
6441
############################################
6542
## adjust memory limit

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*
2121
* Service which allows to sync product widget information, such as product id with db. In order to reuse this info
2222
* on different devices
23+
*
24+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2325
*/
2426
class Synchronizer
2527
{
@@ -94,6 +96,7 @@ public function __construct(
9496
*
9597
* @param string $namespace
9698
* @return int
99+
* @throws \Magento\Framework\Exception\LocalizedException
97100
*/
98101
private function getLifeTimeByNamespace($namespace)
99102
{
@@ -119,6 +122,7 @@ private function getLifeTimeByNamespace($namespace)
119122
* @param array $productsData (product action data, that came from frontend)
120123
* @param string $typeId namespace (type of action)
121124
* @return array
125+
* @throws \Magento\Framework\Exception\LocalizedException
122126
*/
123127
private function filterNewestActions(array $productsData, $typeId)
124128
{
@@ -166,6 +170,7 @@ private function getProductIdsByActions(array $actions)
166170
* @param array $productsData
167171
* @param string $typeId
168172
* @return void
173+
* @throws \Exception
169174
*/
170175
public function syncActions(array $productsData, $typeId)
171176
{
@@ -189,16 +194,15 @@ public function syncActions(array $productsData, $typeId)
189194
foreach ($collection as $item) {
190195
$this->entityManager->delete($item);
191196
}
192-
193-
foreach ($productsData as $productId => $productData) {
197+
foreach ($productsData as $productData) {
194198
/** @var ProductFrontendActionInterface $action */
195199
$action = $this->productFrontendActionFactory->create(
196200
[
197201
'data' => [
198202
'visitor_id' => $customerId ? null : $visitorId,
199203
'customer_id' => $this->session->getCustomerId(),
200204
'added_at' => $productData['added_at'],
201-
'product_id' => $productId,
205+
'product_id' => $productData['product_id'],
202206
'type_id' => $typeId
203207
]
204208
]

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,7 @@ protected function _productLimitationJoinPrice()
19111911
* @param bool $joinLeft
19121912
* @return $this
19131913
* @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
1914+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
19141915
*/
19151916
protected function _productLimitationPrice($joinLeft = false)
19161917
{
@@ -1929,14 +1930,14 @@ protected function _productLimitationPrice($joinLeft = false)
19291930

19301931
$connection = $this->getConnection();
19311932
$select = $this->getSelect();
1932-
$joinCond = join(
1933-
' AND ',
1934-
[
1935-
'price_index.entity_id = e.entity_id',
1936-
$connection->quoteInto('price_index.website_id = ?', $filters['website_id']),
1937-
$connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])
1938-
]
1939-
);
1933+
$joinCondArray = [];
1934+
$joinCondArray[] = 'price_index.entity_id = e.entity_id';
1935+
$joinCondArray[] = $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id']);
1936+
// Add website condition only if it's different from admin scope
1937+
if (((int) $filters['website_id']) !== Store::DEFAULT_STORE_ID) {
1938+
$joinCondArray[] = $connection->quoteInto('price_index.website_id = ?', $filters['website_id']);
1939+
}
1940+
$joinCond = join(' AND ', $joinCondArray);
19401941

19411942
$fromPart = $select->getPart(\Magento\Framework\DB\Select::FROM);
19421943
if (!isset($fromPart['price_index'])) {

app/code/Magento/Catalog/Test/Unit/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public function testFilterProductActions()
8282
{
8383
$typeId = 'recently_compared_product';
8484
$productsData = [
85-
1 => [
85+
'website-1-1' => [
8686
'added_at' => 12,
8787
'product_id' => 1,
8888
],
89-
2 => [
89+
'website-1-2' => [
9090
'added_at' => 13,
9191
'product_id' => '2',
9292
],
93-
3 => [
93+
'website-2-3' => [
9494
'added_at' => 14,
9595
'product_id' => 3,
9696
]

app/code/Magento/Catalog/view/frontend/templates/product/image.phtml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66
?>
7-
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
7+
<?php
8+
/** @var $block \Magento\Catalog\Block\Product\Image */
9+
/** @var $escaper \Magento\Framework\Escaper */
10+
?>
811

9-
<img class="photo image <?= $block->escapeHtmlAttr($block->getClass()) ?>"
10-
<?= $block->escapeHtml($block->getCustomAttributes()) ?>
11-
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
12-
width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
13-
height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
14-
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>" />
12+
<img class="photo image <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
13+
<?= $escaper->escapeHtml($block->getCustomAttributes()) ?>
14+
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
15+
loading="lazy"
16+
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
17+
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
18+
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>" />

app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
* See COPYING.txt for license details.
55
*/
66
?>
7-
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
7+
<?php
8+
/** @var $block \Magento\Catalog\Block\Product\Image */
9+
/** @var $escaper \Magento\Framework\Escaper */
10+
?>
811

912
<span class="product-image-container"
10-
style="width:<?= $block->escapeHtmlAttr($block->getWidth()) ?>px;">
13+
style="width:<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>px;">
1114
<span class="product-image-wrapper"
1215
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
13-
<img class="<?= $block->escapeHtmlAttr($block->getClass()) ?>"
14-
<?= $block->escapeHtmlAttr($block->getCustomAttributes()) ?>
15-
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
16-
max-width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
17-
max-height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
18-
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>"/></span>
16+
<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
17+
<?= $escaper->escapeHtmlAttr($block->getCustomAttributes()) ?>
18+
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
19+
loading="lazy"
20+
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
21+
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
22+
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
1923
</span>

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
307307
// Can't add new translated strings in patch release
308308
'invalidLayoutUpdate' => 'Invalid format.',
309309
'insufficientPermissions' => 'Invalid format.',
310+
ValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES => 'SKU contains marginal whitespaces'
310311
];
311312
//@codingStandardsIgnoreEnd
312313

app/code/Magento/CatalogImportExport/Model/Import/Product/RowValidatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn
8787

8888
const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';
8989

90+
const ERROR_SKU_MARGINAL_WHITESPACES = 'skuMarginalWhitespaces';
91+
9092
/**
9193
* Value that means all entities (e.g. websites, groups etc.)
9294
*/

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
1111

1212
/**
13-
* Class Validator
13+
* Product import model validator
1414
*
1515
* @api
1616
* @since 100.0.2
@@ -72,8 +72,12 @@ protected function textValidation($attrCode, $type)
7272
$val = $this->string->cleanString($this->_rowData[$attrCode]);
7373
if ($type == 'text') {
7474
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
75-
} else if ($attrCode == Product::COL_SKU) {
75+
} elseif ($attrCode == Product::COL_SKU) {
7676
$valid = $this->string->strlen($val) <= SKU::SKU_MAX_LENGTH;
77+
if ($this->string->strlen($val) !== $this->string->strlen(trim($val))) {
78+
$this->_addMessages([RowValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES]);
79+
return false;
80+
}
7781
} else {
7882
$valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
7983
}
@@ -359,5 +363,7 @@ public function init($context)
359363
foreach ($this->validators as $validator) {
360364
$validator->init($context);
361365
}
366+
367+
return $this;
362368
}
363369
}

app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Magento\Catalog\Api\Data\ProductInterface;
1313
use Magento\Catalog\Model\ProductCategoryList;
14+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1415
use Magento\Store\Model\Store;
1516

1617
/**
@@ -122,59 +123,47 @@ protected function _addSpecialAttributes(array &$attributes)
122123
/**
123124
* Add condition to collection
124125
*
125-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
126+
* @param Collection $collection
126127
* @return $this
127128
*/
128129
public function addToCollection($collection)
129130
{
130131
$attribute = $this->getAttributeObject();
132+
$attributeCode = $attribute->getAttributeCode();
133+
if ($attributeCode !== 'price' || !$collection->getLimitationFilters()->isUsingPriceIndex()) {
134+
if ($collection->isEnabledFlat()) {
135+
if ($attribute->isEnabledInFlat()) {
136+
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
137+
$this->joinedAttributes[$attributeCode] = $alias . '.' . $attributeCode;
138+
} else {
139+
$alias = 'at_' . $attributeCode;
140+
if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) {
141+
$collection->joinAttribute($attributeCode, "catalog_product/$attributeCode", 'entity_id');
142+
}
131143

132-
if ($collection->isEnabledFlat()) {
133-
if ($attribute->isEnabledInFlat()) {
134-
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
135-
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
136-
} else {
137-
$alias = 'at_' . $attribute->getAttributeCode();
138-
if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) {
139-
$collection->joinAttribute(
140-
$attribute->getAttributeCode(),
141-
'catalog_product/'.$attribute->getAttributeCode(),
142-
'entity_id'
143-
);
144+
$this->joinedAttributes[$attributeCode] = $alias . '.value';
144145
}
145-
146-
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
146+
} elseif ($attributeCode !== 'category_ids' && !$attribute->isStatic()) {
147+
$this->addAttributeToCollection($attribute, $collection);
148+
$attributes = $this->getRule()->getCollectedAttributes();
149+
$attributes[$attributeCode] = true;
150+
$this->getRule()->setCollectedAttributes($attributes);
147151
}
148-
return $this;
149152
}
150153

151-
if ('category_ids' == $attribute->getAttributeCode() || $attribute->isStatic()) {
152-
return $this;
153-
}
154-
155-
if ($attribute->getBackend() && $attribute->isScopeGlobal()) {
156-
$this->addGlobalAttribute($attribute, $collection);
157-
} else {
158-
$this->addNotGlobalAttribute($attribute, $collection);
159-
}
160-
161-
$attributes = $this->getRule()->getCollectedAttributes();
162-
$attributes[$attribute->getAttributeCode()] = true;
163-
$this->getRule()->setCollectedAttributes($attributes);
164-
165154
return $this;
166155
}
167156

168157
/**
169158
* Adds Attributes that belong to Global Scope
170159
*
171160
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
172-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
161+
* @param Collection $collection
173162
* @return $this
174163
*/
175164
protected function addGlobalAttribute(
176165
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
177-
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
166+
Collection $collection
178167
) {
179168
switch ($attribute->getBackendType()) {
180169
case 'decimal':
@@ -207,12 +196,12 @@ protected function addGlobalAttribute(
207196
* Adds Attributes that don't belong to Global Scope
208197
*
209198
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
210-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
199+
* @param Collection $collection
211200
* @return $this
212201
*/
213202
protected function addNotGlobalAttribute(
214203
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
215-
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
204+
Collection $collection
216205
) {
217206
$storeId = $this->storeManager->getStore()->getId();
218207
$values = $collection->getAllAttributeValues($attribute);
@@ -255,6 +244,8 @@ public function getMappedSqlField()
255244
$result = parent::getMappedSqlField();
256245
} elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
257246
$result = $this->joinedAttributes[$this->getAttribute()];
247+
} elseif ($this->getAttribute() === 'price') {
248+
$result = 'price_index.min_price';
258249
} elseif ($this->getAttributeObject()->isStatic()) {
259250
$result = $this->getAttributeObject()->getAttributeCode();
260251
} elseif ($this->getValueParsed()) {
@@ -267,11 +258,27 @@ public function getMappedSqlField()
267258
/**
268259
* @inheritdoc
269260
*
270-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
261+
* @param Collection $productCollection
271262
* @return $this
272263
*/
273264
public function collectValidatedAttributes($productCollection)
274265
{
275266
return $this->addToCollection($productCollection);
276267
}
268+
269+
/**
270+
* Add attribute to collection based on scope
271+
*
272+
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
273+
* @param Collection $collection
274+
* @return void
275+
*/
276+
private function addAttributeToCollection($attribute, $collection): void
277+
{
278+
if ($attribute->getBackend() && $attribute->isScopeGlobal()) {
279+
$this->addGlobalAttribute($attribute, $collection);
280+
} else {
281+
$this->addNotGlobalAttribute($attribute, $collection);
282+
}
283+
}
277284
}

0 commit comments

Comments
 (0)