Skip to content

Commit 04dd963

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents c865afa + 41042e7 commit 04dd963

File tree

10 files changed

+160
-20
lines changed

10 files changed

+160
-20
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/Query/BaseFinalPrice.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,8 @@ public function getQuery(array $dimensions, string $productType, array $entityId
221221
$select->where("e.type_id = ?", $productType);
222222

223223
if ($entityIds !== null) {
224-
if (count($entityIds) > 1) {
225-
$select->where(sprintf('e.entity_id BETWEEN %s AND %s', min($entityIds), max($entityIds)));
226-
} else {
227-
$select->where('e.entity_id = ?', $entityIds);
228-
}
224+
$select->where(sprintf('e.entity_id BETWEEN %s AND %s', min($entityIds), max($entityIds)));
225+
$select->where('e.entity_id IN(?)', $entityIds);
229226
}
230227

231228
/**

app/code/Magento/Catalog/Pricing/Render/PriceBox.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Pricing\Render;
79

810
use Magento\Catalog\Model\Product;
@@ -71,7 +73,9 @@ public function jsonEncode($valueToEncode)
7173
*
7274
* @param int $length
7375
* @param string|null $chars
76+
*
7477
* @return string
78+
* @throws \Magento\Framework\Exception\LocalizedException
7579
*/
7680
public function getRandomString($length, $chars = null)
7781
{
@@ -93,4 +97,21 @@ public function getCanDisplayQty(Product $product)
9397
}
9498
return true;
9599
}
100+
101+
/**
102+
* Format percent
103+
*
104+
* @param float $percent
105+
*
106+
* @return string
107+
*/
108+
public function formatPercent(float $percent): string
109+
{
110+
/*First rtrim - trim zeros. So, 10.00 -> 10.*/
111+
/*Second rtrim - trim dot. So, 10. -> 10*/
112+
return rtrim(
113+
rtrim(number_format($percent, 2), '0'),
114+
'.'
115+
);
116+
}
96117
}

app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $product = $block->getSaleableItem();
7777
$price['price_qty'],
7878
$priceAmountBlock,
7979
$index,
80-
$tierPriceModel->getSavePercent($price['price'])
80+
$block->formatPercent($price['percentage_value'] ?? $tierPriceModel->getSavePercent($price['price']))
8181
)
8282
: __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock);
8383
?>

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ protected function _parseVariations($rowData)
596596
$additionalRow['_super_attribute_position'] = $position;
597597
$additionalRows[] = $additionalRow;
598598
$additionalRow = [];
599-
$position += 1;
599+
$position ++;
600600
}
601601
} else {
602602
throw new LocalizedException(
@@ -937,7 +937,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
937937
}
938938
foreach ($dataWithExtraVirtualRows as $option) {
939939
if (isset($option['_super_products_sku'])) {
940-
if (in_array($option['_super_products_sku'], $skus)) {
940+
if (in_array($option['_super_products_sku'], $skus, true)) {
941941
$error = true;
942942
$this->_entityModel->addRowError(
943943
sprintf(

app/code/Magento/ConfigurableImportExport/Test/Unit/Model/Import/Product/Type/ConfigurableTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,83 @@ public function testIsRowValid()
616616
}
617617
}
618618

619+
public function testRowValidationForNumericalSkus()
620+
{
621+
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
622+
$this->setPropertyValue($this->configurable, '_attributes', [
623+
'Default' => [],
624+
]);
625+
// Avoiding errors about attributes not being super
626+
$this->setPropertyValue(
627+
$this->configurable,
628+
'_superAttributes',
629+
[
630+
'testattr2' => [
631+
'options' => [
632+
'attr2val1' => 1,
633+
'attr2val2' => 2,
634+
]
635+
],
636+
]
637+
);
638+
639+
$rowValidationDataProvider = $this->rowValidationDataProvider();
640+
641+
// Checking that variations with duplicate sku are invalid
642+
$result = $this->configurable->isRowValid($rowValidationDataProvider['duplicateProduct'], 0);
643+
$this->assertFalse($result);
644+
645+
// Checking that variations with SKUs that are the same when interpreted as number,
646+
// but different when interpreted as string are valid
647+
$result = $this->configurable->isRowValid($rowValidationDataProvider['nonDuplicateProduct'], 0);
648+
$this->assertTrue($result);
649+
}
650+
651+
/**
652+
* @return array
653+
*/
654+
public function rowValidationDataProvider()
655+
{
656+
return [
657+
'duplicateProduct' => [
658+
'sku' => 'configurableNumericalSkuDuplicateVariation',
659+
'store_view_code' => null,
660+
'attribute_set_code' => 'Default',
661+
'product_type' => 'configurable',
662+
'name' => 'Configurable Product with duplicate numerical SKUs in variations',
663+
'product_websites' => 'website_1',
664+
'configurable_variation_labels' => 'testattr2=Select Configuration',
665+
'configurable_variations' => 'sku=1234.1,'
666+
. 'testattr2=attr2val1,'
667+
. 'display=1|sku=1234.1,'
668+
. 'testattr2=attr2val1,'
669+
. 'display=0',
670+
'_store' => null,
671+
'_attribute_set' => 'Default',
672+
'_type' => 'configurable',
673+
'_product_websites' => 'website_1',
674+
],
675+
'nonDuplicateProduct' => [
676+
'sku' => 'configurableNumericalSkuNonDuplicateVariation',
677+
'store_view_code' => null,
678+
'attribute_set_code' => 'Default',
679+
'product_type' => 'configurable',
680+
'name' => 'Configurable Product with different numerical SKUs in variations',
681+
'product_websites' => 'website_1',
682+
'configurable_variation_labels' => 'testattr2=Select Configuration',
683+
'configurable_variations' => 'sku=1234.10,'
684+
. 'testattr2=attr2val1,'
685+
. 'display=1|sku=1234.1,'
686+
. 'testattr2=attr2val2,'
687+
. 'display=0',
688+
'_store' => null,
689+
'_attribute_set' => 'Default',
690+
'_type' => 'configurable',
691+
'_product_websites' => 'website_1',
692+
]
693+
];
694+
}
695+
619696
/**
620697
* Set object property value.
621698
*

app/code/Magento/Review/view/frontend/web/js/process-reviews.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ define([
4141
requiredReviewTabRole = 'tab';
4242

4343
if (reviewTab.attr('role') === requiredReviewTabRole && reviewTab.hasClass('active')) {
44-
processReviews(config.productReviewUrl);
44+
processReviews(config.productReviewUrl, location.hash === '#reviews');
4545
} else {
4646
reviewTab.one('beforeOpen', function () {
4747
processReviews(config.productReviewUrl);

app/code/Magento/Theme/Model/Design/Backend/File.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Framework\UrlInterface;
2222
use Magento\MediaStorage\Model\File\UploaderFactory;
2323
use Magento\Theme\Model\Design\Config\FileUploader\FileProcessor;
24+
use Magento\MediaStorage\Helper\File\Storage\Database;
2425

2526
/**
2627
* File Backend
@@ -39,6 +40,11 @@ class File extends BackendFile
3940
*/
4041
private $mime;
4142

43+
/**
44+
* @var Database
45+
*/
46+
private $databaseHelper;
47+
4248
/**
4349
* @param Context $context
4450
* @param Registry $registry
@@ -51,6 +57,7 @@ class File extends BackendFile
5157
* @param AbstractResource|null $resource
5258
* @param AbstractDb|null $resourceCollection
5359
* @param array $data
60+
* @param Database $databaseHelper
5461
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5562
*/
5663
public function __construct(
@@ -64,7 +71,8 @@ public function __construct(
6471
UrlInterface $urlBuilder,
6572
AbstractResource $resource = null,
6673
AbstractDb $resourceCollection = null,
67-
array $data = []
74+
array $data = [],
75+
Database $databaseHelper = null
6876
) {
6977
parent::__construct(
7078
$context,
@@ -79,6 +87,7 @@ public function __construct(
7987
$data
8088
);
8189
$this->urlBuilder = $urlBuilder;
90+
$this->databaseHelper = $databaseHelper ?: ObjectManager::getInstance()->get(Database::class);
8291
}
8392

8493
/**
@@ -103,7 +112,7 @@ public function beforeSave()
103112
$this->setValue($file);
104113
return $this;
105114
}
106-
115+
107116
//phpcs:ignore Magento2.Functions.DiscouragedFunction
108117
$this->updateMediaDirectory(basename($file), $value['url']);
109118

@@ -261,6 +270,10 @@ private function updateMediaDirectory(string $filename, string $url)
261270
$mediaPath,
262271
$destinationMediaPath
263272
);
273+
$this->databaseHelper->renameFile(
274+
$mediaPath,
275+
$destinationMediaPath
276+
);
264277
}
265278
if ($result) {
266279
if ($mediaPath === $tmpMediaPath) {

app/code/Magento/Theme/Test/Unit/Model/Design/Backend/FileTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class FileTest extends \PHPUnit\Framework\TestCase
2828
*/
2929
private $mime;
3030

31+
/**
32+
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $databaseHelper;
35+
3136
public function setUp()
3237
{
3338
$context = $this->getMockObject(\Magento\Framework\Model\Context::class);
@@ -55,6 +60,17 @@ public function setUp()
5560
->disableOriginalConstructor()
5661
->getMock();
5762

63+
$this->databaseHelper = $this->getMockBuilder(\Magento\MediaStorage\Helper\File\Storage\Database::class)
64+
->disableOriginalConstructor()
65+
->getMock();
66+
67+
$abstractResource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class)
68+
->getMockForAbstractClass();
69+
70+
$abstractDb = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
71+
->disableOriginalConstructor()
72+
->getMockForAbstractClass();
73+
5874
$this->fileBackend = new File(
5975
$context,
6076
$registry,
@@ -63,7 +79,11 @@ public function setUp()
6379
$uploaderFactory,
6480
$requestData,
6581
$filesystem,
66-
$this->urlBuilder
82+
$this->urlBuilder,
83+
$abstractResource,
84+
$abstractDb,
85+
[],
86+
$this->databaseHelper
6787
);
6888

6989
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -196,6 +216,11 @@ public function testBeforeSave($fileName)
196216
]
197217
);
198218

219+
$this->databaseHelper->expects($this->once())
220+
->method('renameFile')
221+
->with($expectedTmpMediaPath, '/' . $expectedFileName)
222+
->willReturn(true);
223+
199224
$this->mediaDirectory->expects($this->once())
200225
->method('copyFile')
201226
->with($expectedTmpMediaPath, '/' . $expectedFileName)

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
196196
public function scopeDate($scope = null, $date = null, $includeTime = false)
197197
{
198198
$timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope);
199-
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date, new \DateTimeZone($timezone));
199+
$date = new \DateTime(is_numeric($date) ? '@' . $date : $date);
200+
$date->setTimezone(new \DateTimeZone($timezone));
200201
if (!$includeTime) {
201202
$date->setTime(0, 0, 0);
202203
}
@@ -247,13 +248,8 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
247248
$toTimeStamp += 86400;
248249
}
249250

250-
$result = false;
251-
if (!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp) {
252-
} elseif (!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp) {
253-
} else {
254-
$result = true;
255-
}
256-
return $result;
251+
return !(!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp ||
252+
!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp);
257253
}
258254

259255
/**

lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,15 @@ private function scopeConfigWillReturnConfiguredTimezone($configuredTimezone)
253253
{
254254
$this->scopeConfig->method('getValue')->with('', '', null)->willReturn($configuredTimezone);
255255
}
256+
257+
public function testCheckIfScopeDateSetsTimeZone()
258+
{
259+
$scopeDate = new \DateTime('now', new \DateTimeZone('America/Vancouver'));
260+
$this->scopeConfig->method('getValue')->willReturn('America/Vancouver');
261+
262+
$this->assertEquals(
263+
$scopeDate->getTimezone(),
264+
$this->getTimezone()->scopeDate(0, $scopeDate->getTimestamp())->getTimezone()
265+
);
266+
}
256267
}

0 commit comments

Comments
 (0)