Skip to content

Commit 8170336

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #20328: [Backport] Fix issue 20232 : Backend order credit card detail check box misaligned (by @GovindaSharma) - #20325: [Backport] issus fixed #20158 Store switcher not aligned proper in tab view (by @shikhamis11) - #20353: Fixed#20352: displaying html content for file type option on order view admin area (by @maheshWebkul721) - #20329: [Backport] Product image failure when importing through CSV #20098 (by @irajneeshgupta) - #20298: ISSUE-20296: "@magentoDataIsolation" is used instead of "@magentoDbIsolation" in some integration tests. (by @p-bystritsky) - #20185: [Backport] Move website_name column into columnSet (by @mage2pratik) - #20286: [Backport] Don't return categoryId from registry if the product doesn't belong in the current category (by @GovindaSharma) - #20271: [Backport] Use the new json serializer which throws an error when failing (by @quisse) - #20183: 2.2 develop pr port 18888 (by @saphaljha) - #20178: #16198: Category image remain after deleted. (by @p-bystritsky) Fixed GitHub Issues: - #20232: Backend order credit card detail check box misaligned (reported by @speedy008) has been fixed in #20328 by @GovindaSharma in 2.2-develop branch Related commits: 1. 6c5cba7 - #20158: Store switcher not aligned proper in tab view (reported by @cedarvinda) has been fixed in #20325 by @shikhamis11 in 2.2-develop branch Related commits: 1. f9a03d8 2. 82ad1ca - #20352: File type option value shows html content in admin order view. (reported by @maheshWebkul721) has been fixed in #20353 by @maheshWebkul721 in 2.2-develop branch Related commits: 1. c0730dc - #20098: Product image failure when importing through CSV (reported by @flytomek) has been fixed in #20329 by @irajneeshgupta in 2.2-develop branch Related commits: 1. 40f64f9 - #20296: "@magentoDataIsolation" is used instead of "@magentoDbIsolation" in some integration tests. (reported by @p-bystritsky) has been fixed in #20298 by @p-bystritsky in 2.2-develop branch Related commits: 1. de64b09 - #17819: Wrong product url from getProductUrl when current category has not product object (reported by @OleksiiBulba) has been fixed in #20286 by @GovindaSharma in 2.2-develop branch Related commits: 1. 0247fc3 - #14937: Javascript error thrown from uiComponent 'notification_area' if messages are malformed (reported by @sylvainraye) has been fixed in #20271 by @quisse in 2.2-develop branch Related commits: 1. 7e3ea1b 2. f72fb42 3. dbb905c 4. c3f4d5d 5. 31bf4b2 - #18192: Backend issue : "ratings isn't available" website wise (reported by @hardik-krish) has been fixed in #20183 by @saphaljha in 2.2-develop branch Related commits: 1. 06443f9 2. cb6ff7e 3. 56a0f11 4. 9c59356 5. fd4dd39 6. a26b9bd 7. 30a6d5a - #16198: Category image remain after deleted (reported by @vincent2090311) has been fixed in #20178 by @p-bystritsky in 2.2-develop branch Related commits: 1. 3b4581c 2. 979e552
2 parents 530e0d1 + 2e38840 commit 8170336

File tree

24 files changed

+540
-34
lines changed

24 files changed

+540
-34
lines changed

app/code/Magento/Braintree/view/adminhtml/templates/form/cc.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ $ccType = $block->getInfoData('cc_type');
8383
id="<?= /* @noEscape */ $code ?>_vault"
8484
name="payment[is_active_payment_token_enabler]"
8585
class="admin__control-checkbox"/>
86-
<label class="label" for="<?= /* @noEscape */ $code ?>_vault">
86+
<label class="label admin__field-label" for="<?= /* @noEscape */ $code ?>_vault">
8787
<span><?= $block->escapeHtml(__('Save for later use.')) ?></span>
8888
</label>
8989
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ public function getIdBySku($sku)
714714
public function getCategoryId()
715715
{
716716
$category = $this->_registry->registry('current_category');
717-
if ($category) {
717+
if ($category && in_array($category->getId(), $this->getCategoryIds())) {
718718
return $category->getId();
719719
}
720720
return false;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ResourceModel\Category;
9+
10+
use Magento\Catalog\Api\CategoryListInterface;
11+
use Magento\Framework\Api\SearchCriteriaBuilder;
12+
13+
/**
14+
* Check if Image is currently used in any category as Category Image.
15+
*/
16+
class RedundantCategoryImageChecker
17+
{
18+
/**
19+
* @var SearchCriteriaBuilder
20+
*/
21+
private $searchCriteriaBuilder;
22+
23+
/**
24+
* @var CategoryListInterface
25+
*/
26+
private $categoryList;
27+
28+
public function __construct(
29+
CategoryListInterface $categoryList,
30+
SearchCriteriaBuilder $searchCriteriaBuilder
31+
) {
32+
$this->categoryList = $categoryList;
33+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
34+
}
35+
36+
/**
37+
* Checks if Image is currently used in any category as Category Image.
38+
*
39+
* Returns true if not.
40+
*
41+
* @param string $imageName
42+
* @return bool
43+
*/
44+
public function execute(string $imageName): bool
45+
{
46+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
47+
$searchCriteria = $this->searchCriteriaBuilder->addFilter('image', $imageName)->create();
48+
$categories = $this->categoryList->getList($searchCriteria)->getItems();
49+
50+
return empty($categories);
51+
}
52+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Plugin\Model\ResourceModel\Category;
9+
10+
use Magento\Catalog\Model\ImageUploader;
11+
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
12+
use Magento\Catalog\Model\ResourceModel\Category\RedundantCategoryImageChecker;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Filesystem;
15+
use Magento\Framework\Model\AbstractModel;
16+
17+
/**
18+
* Remove old Category Image file from pub/media/catalog/category directory if such Image is not used anymore.
19+
*/
20+
class RemoveRedundantImagePlugin
21+
{
22+
/**
23+
* @var Filesystem
24+
*/
25+
private $filesystem;
26+
27+
/**
28+
* @var ImageUploader
29+
*/
30+
private $imageUploader;
31+
32+
/**
33+
* @var RedundantCategoryImageChecker
34+
*/
35+
private $redundantCategoryImageChecker;
36+
37+
public function __construct(
38+
Filesystem $filesystem,
39+
ImageUploader $imageUploader,
40+
RedundantCategoryImageChecker $redundantCategoryImageChecker
41+
) {
42+
$this->filesystem = $filesystem;
43+
$this->imageUploader = $imageUploader;
44+
$this->redundantCategoryImageChecker = $redundantCategoryImageChecker;
45+
}
46+
47+
/**
48+
* Removes Image file if it is not used anymore.
49+
*
50+
* @param CategoryResource $subject
51+
* @param CategoryResource $result
52+
* @param AbstractModel $category
53+
* @return CategoryResource
54+
*
55+
* @throws \Magento\Framework\Exception\FileSystemException
56+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
57+
*/
58+
public function afterSave(
59+
CategoryResource $subject,
60+
CategoryResource $result,
61+
AbstractModel $category
62+
): CategoryResource {
63+
$originalImage = $category->getOrigData('image');
64+
if (null !== $originalImage
65+
&& $originalImage !== $category->getImage()
66+
&& $this->redundantCategoryImageChecker->execute($originalImage)
67+
) {
68+
$basePath = $this->imageUploader->getBasePath();
69+
$baseImagePath = $this->imageUploader->getFilePath($basePath, $originalImage);
70+
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
71+
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
72+
$mediaDirectory->delete($baseImagePath);
73+
}
74+
75+
return $result;
76+
}
77+
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ public function testSetCategoryCollection()
543543

544544
public function testGetCategory()
545545
{
546+
$this->model->setData('category_ids', [10]);
546547
$this->category->expects($this->any())->method('getId')->will($this->returnValue(10));
547548
$this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->category));
548549
$this->categoryRepository->expects($this->any())->method('get')->will($this->returnValue($this->category));
@@ -551,14 +552,23 @@ public function testGetCategory()
551552

552553
public function testGetCategoryId()
553554
{
554-
$this->category->expects($this->once())->method('getId')->will($this->returnValue(10));
555+
$this->model->setData('category_ids', [10]);
556+
$this->category->expects($this->any())->method('getId')->will($this->returnValue(10));
555557

556558
$this->registry->expects($this->at(0))->method('registry');
557559
$this->registry->expects($this->at(1))->method('registry')->will($this->returnValue($this->category));
558560
$this->assertFalse($this->model->getCategoryId());
559561
$this->assertEquals(10, $this->model->getCategoryId());
560562
}
561563

564+
public function testGetCategoryIdWhenProductNotInCurrentCategory()
565+
{
566+
$this->model->setData('category_ids', [12]);
567+
$this->category->expects($this->once())->method('getId')->will($this->returnValue(10));
568+
$this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->category));
569+
$this->assertFalse($this->model->getCategoryId());
570+
}
571+
562572
public function testGetIdBySku()
563573
{
564574
$this->resource->expects($this->once())->method('getIdBySku')->will($this->returnValue(5));

app/code/Magento/Catalog/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,14 @@
907907
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
908908
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
909909
</type>
910+
<type name="Magento\Catalog\Model\ResourceModel\Category">
911+
<plugin name="remove_redundant_image" type="Magento\Catalog\Plugin\Model\ResourceModel\Category\RemoveRedundantImagePlugin"/>
912+
</type>
913+
<type name="Magento\Catalog\Plugin\Model\ResourceModel\Category\RemoveRedundantImagePlugin">
914+
<arguments>
915+
<argument name="imageUploader" xsi:type="object">Magento\Catalog\CategoryImageUpload</argument>
916+
</arguments>
917+
</type>
910918
<preference for="Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface" type="Magento\Catalog\Model\ResourceModel\Product\CompositeWithWebsiteProcessor" />
911919
<type name="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor">
912920
<arguments>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public function move($fileName, $renameFileOff = false)
191191
}
192192

193193
$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
194-
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
194+
$relativePath = $this->_directory->getRelativePath($filePath . $fileName);
195195
$this->_directory->writeFile(
196-
$filePath,
196+
$relativePath,
197197
$read->readAll()
198198
);
199199
}

app/code/Magento/Checkout/Block/Onepage.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Onepage extends \Magento\Framework\View\Element\Template
3838
protected $layoutProcessors;
3939

4040
/**
41-
* @var \Magento\Framework\Serialize\Serializer\Json
41+
* @var \Magento\Framework\Serialize\SerializerInterface
4242
*/
4343
private $serializer;
4444

@@ -48,37 +48,39 @@ class Onepage extends \Magento\Framework\View\Element\Template
4848
* @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
4949
* @param array $layoutProcessors
5050
* @param array $data
51-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
52-
* @throws \RuntimeException
51+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
52+
* @param \Magento\Framework\Serialize\SerializerInterface $serializerInterface
53+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5354
*/
5455
public function __construct(
5556
\Magento\Framework\View\Element\Template\Context $context,
5657
\Magento\Framework\Data\Form\FormKey $formKey,
5758
\Magento\Checkout\Model\CompositeConfigProvider $configProvider,
5859
array $layoutProcessors = [],
5960
array $data = [],
60-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
61+
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
62+
\Magento\Framework\Serialize\SerializerInterface $serializerInterface = null
6163
) {
6264
parent::__construct($context, $data);
6365
$this->formKey = $formKey;
6466
$this->_isScopePrivate = true;
6567
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
6668
$this->configProvider = $configProvider;
6769
$this->layoutProcessors = $layoutProcessors;
68-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
69-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
70+
$this->serializer = $serializerInterface ?: \Magento\Framework\App\ObjectManager::getInstance()
71+
->get(\Magento\Framework\Serialize\Serializer\JsonHexTag::class);
7072
}
7173

7274
/**
73-
* @return string
75+
* @inheritdoc
7476
*/
7577
public function getJsLayout()
7678
{
7779
foreach ($this->layoutProcessors as $processor) {
7880
$this->jsLayout = $processor->process($this->jsLayout);
7981
}
8082

81-
return json_encode($this->jsLayout, JSON_HEX_TAG);
83+
return $this->serializer->serialize($this->jsLayout);
8284
}
8385

8486
/**
@@ -115,11 +117,13 @@ public function getBaseUrl()
115117
}
116118

117119
/**
120+
* Retrieve serialized checkout config.
121+
*
118122
* @return bool|string
119123
* @since 100.2.0
120124
*/
121125
public function getSerializedCheckoutConfig()
122126
{
123-
return json_encode($this->getCheckoutConfig(), JSON_HEX_TAG);
127+
return $this->serializer->serialize($this->getCheckoutConfig());
124128
}
125129
}

app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OnepageTest extends \PHPUnit\Framework\TestCase
3535
/**
3636
* @var \PHPUnit_Framework_MockObject_MockObject
3737
*/
38-
private $serializer;
38+
private $serializerMock;
3939

4040
protected function setUp()
4141
{
@@ -49,15 +49,16 @@ protected function setUp()
4949
\Magento\Checkout\Block\Checkout\LayoutProcessorInterface::class
5050
);
5151

52-
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
52+
$this->serializerMock = $this->createMock(\Magento\Framework\Serialize\Serializer\JsonHexTag::class);
5353

5454
$this->model = new \Magento\Checkout\Block\Onepage(
5555
$contextMock,
5656
$this->formKeyMock,
5757
$this->configProviderMock,
5858
[$this->layoutProcessorMock],
5959
[],
60-
$this->serializer
60+
$this->serializerMock,
61+
$this->serializerMock
6162
);
6263
}
6364

@@ -93,6 +94,7 @@ public function testGetJsLayout()
9394
$processedLayout = ['layout' => ['processed' => true]];
9495
$jsonLayout = '{"layout":{"processed":true}}';
9596
$this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout);
97+
$this->serializerMock->expects($this->once())->method('serialize')->willReturn($jsonLayout);
9698

9799
$this->assertEquals($jsonLayout, $this->model->getJsLayout());
98100
}
@@ -101,6 +103,7 @@ public function testGetSerializedCheckoutConfig()
101103
{
102104
$checkoutConfig = ['checkout', 'config'];
103105
$this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
106+
$this->serializerMock->expects($this->once())->method('serialize')->willReturn(json_encode($checkoutConfig));
104107

105108
$this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig());
106109
}

app/code/Magento/Checkout/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<item name="totalsSortOrder" xsi:type="object">Magento\Checkout\Block\Checkout\TotalsProcessor</item>
6060
<item name="directoryData" xsi:type="object">Magento\Checkout\Block\Checkout\DirectoryDataProcessor</item>
6161
</argument>
62+
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\JsonHexTag</argument>
6263
</arguments>
6364
</type>
6465
<type name="Magento\Checkout\Block\Cart\Totals">

0 commit comments

Comments
 (0)