Skip to content

Commit 70cf0c2

Browse files
authored
Merge pull request #5490 from magento-tsg-csl3/2.4-develop-pr19
[TSG-CSL3] For 2.4 (pr19)
2 parents 9ba1009 + c18dee6 commit 70cf0c2

File tree

29 files changed

+945
-122
lines changed

29 files changed

+945
-122
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
1616
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1717

18+
/**
19+
* Update catalog_product_index_price table after delete or save customer group
20+
*/
1821
class CustomerGroup
1922
{
2023
/**
@@ -80,7 +83,7 @@ public function aroundSave(
8083
\Closure $proceed,
8184
GroupInterface $group
8285
) {
83-
$isGroupNew = !$group->getId();
86+
$isGroupNew = $group->getId() === null;
8487
$group = $proceed($group);
8588
if ($isGroupNew) {
8689
foreach ($this->getAffectedDimensions((string)$group->getId()) as $dimensions) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Plugin;
7+
8+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration;
9+
use Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup;
10+
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
11+
use Magento\Customer\Api\GroupRepositoryInterface;
12+
use Magento\Customer\Model\Data\Group;
13+
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
14+
use Magento\Framework\Indexer\DimensionFactory;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
18+
/**
19+
* Test for CustomerGroup plugin
20+
*/
21+
class CustomerGroupTest extends \PHPUnit\Framework\TestCase
22+
{
23+
/**
24+
* @var ObjectManager
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var CustomerGroup
30+
*/
31+
private $model;
32+
33+
/**
34+
* @var DimensionFactory|MockObject
35+
*/
36+
private $dimensionFactory;
37+
38+
/**
39+
* @var TableMaintainer|MockObject
40+
*/
41+
private $tableMaintainerMock;
42+
43+
/**
44+
* @var DimensionModeConfiguration|MockObject
45+
*/
46+
private $dimensionModeConfiguration;
47+
48+
/**
49+
* @var \Callable
50+
*/
51+
private $proceedMock;
52+
53+
protected function setUp()
54+
{
55+
$this->objectManager = new ObjectManager($this);
56+
57+
$this->dimensionFactory = $this->createPartialMock(
58+
DimensionFactory::class,
59+
['create']
60+
);
61+
62+
$this->dimensionModeConfiguration = $this->createPartialMock(
63+
DimensionModeConfiguration::class,
64+
['getDimensionConfiguration']
65+
);
66+
67+
$this->tableMaintainerMock = $this->createPartialMock(
68+
TableMaintainer::class,
69+
['createTablesForDimensions']
70+
);
71+
72+
$this->model = $this->objectManager->getObject(
73+
CustomerGroup::class,
74+
[
75+
'dimensionFactory' => $this->dimensionFactory,
76+
'dimensionModeConfiguration' => $this->dimensionModeConfiguration,
77+
'tableMaintainer' => $this->tableMaintainerMock,
78+
]
79+
);
80+
}
81+
82+
/**
83+
* Check of call count createTablesForDimensions() method
84+
*
85+
* @param $customerGroupId
86+
* @param $callTimes
87+
*
88+
* @dataProvider aroundSaveDataProvider
89+
*/
90+
public function testAroundSave($customerGroupId, $callTimes)
91+
{
92+
$subjectMock = $this->createMock(GroupRepositoryInterface::class);
93+
$customerGroupMock = $this->createPartialMock(
94+
Group::class,
95+
['getId']
96+
);
97+
$customerGroupMock->method('getId')->willReturn($customerGroupId);
98+
$this->tableMaintainerMock->expects(
99+
$this->exactly($callTimes)
100+
)->method('createTablesForDimensions');
101+
$this->proceedMock = function ($customerGroupMock) {
102+
return $customerGroupMock;
103+
};
104+
$this->dimensionModeConfiguration->method('getDimensionConfiguration')->willReturn(
105+
[CustomerGroupDimensionProvider::DIMENSION_NAME]
106+
);
107+
$this->model->aroundSave($subjectMock, $this->proceedMock, $customerGroupMock);
108+
}
109+
110+
/**
111+
* Data provider for testAroundSave
112+
*
113+
* @return array
114+
*/
115+
public function aroundSaveDataProvider()
116+
{
117+
return [
118+
'customer_group_id = 0' => [
119+
'customer_group_id' => '0',
120+
'create_tables_call_times' => 0
121+
],
122+
'customer_group_id = 1' => [
123+
'customer_group_id' => '1',
124+
'create_tables_call_times' => 0
125+
],
126+
'customer_group_id = null' => [
127+
'customer_group_id' => null,
128+
'create_tables_call_times' => 1
129+
],
130+
];
131+
}
132+
}

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/WebsitesTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
77

88
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Websites;
9-
use Magento\Store\Api\WebsiteRepositoryInterface;
109
use Magento\Store\Api\GroupRepositoryInterface;
1110
use Magento\Store\Api\StoreRepositoryInterface;
11+
use Magento\Store\Api\WebsiteRepositoryInterface;
12+
use Magento\Store\Model\Group;
13+
use Magento\Store\Model\Store as StoreView;
1214
use Magento\Store\Model\StoreManagerInterface;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Magento\Store\Model\Website;
15-
use Magento\Store\Model\Store as StoreView;
16-
use Magento\Store\Model\Group;
1716

1817
/**
19-
* Class WebsitesTest
18+
* Class WebsitesTest test the meta data and website data for different websites
2019
*
2120
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2221
*/
@@ -111,7 +110,7 @@ protected function setUp()
111110
->method('getWebsiteIds')
112111
->willReturn($this->assignedWebsites);
113112
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
114-
->setMethods(['isSingleStoreMode', 'getWesites'])
113+
->setMethods(['isSingleStoreMode', 'getWebsites'])
115114
->getMockForAbstractClass();
116115
$this->storeManagerMock->method('getWebsites')
117116
->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
@@ -182,6 +181,14 @@ public function testModifyMeta()
182181
$this->assertTrue(isset($meta['websites']['children'][self::SECOND_WEBSITE_ID]));
183182
$this->assertTrue(isset($meta['websites']['children'][self::WEBSITE_ID]));
184183
$this->assertTrue(isset($meta['websites']['children']['copy_to_stores.' . self::WEBSITE_ID]));
184+
$this->assertEquals(
185+
$meta['websites']['children'][self::SECOND_WEBSITE_ID]['arguments']['data']['config']['value'],
186+
(string) self::SECOND_WEBSITE_ID
187+
);
188+
$this->assertEquals(
189+
$meta['websites']['children'][self::WEBSITE_ID]['arguments']['data']['config']['value'],
190+
"0"
191+
);
185192
}
186193

187194
/**

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Websites.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;
77

88
use Magento\Catalog\Model\Locator\LocatorInterface;
9-
use Magento\Store\Model\StoreManagerInterface;
10-
use Magento\Store\Api\WebsiteRepositoryInterface;
119
use Magento\Store\Api\GroupRepositoryInterface;
1210
use Magento\Store\Api\StoreRepositoryInterface;
13-
use Magento\Ui\Component\Form;
11+
use Magento\Store\Api\WebsiteRepositoryInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
1413
use Magento\Ui\Component\DynamicRows;
14+
use Magento\Ui\Component\Form;
1515

1616
/**
1717
* Class Websites customizes websites panel
@@ -211,6 +211,30 @@ protected function getFieldsForFieldset()
211211
}
212212
}
213213

214+
$children = $this->setDefaultWebsiteIdIfNoneAreSelected($children);
215+
return $children;
216+
}
217+
218+
/**
219+
* Set default website id if none are selected
220+
*
221+
* @param array $children
222+
* @return array
223+
*/
224+
private function setDefaultWebsiteIdIfNoneAreSelected(array $children):array
225+
{
226+
$websitesList = $this->getWebsitesList();
227+
$defaultSelectedWebsite = false;
228+
foreach ($websitesList as $website) {
229+
if ($children[$website['id']]['arguments']['data']['config']['value']) {
230+
$defaultSelectedWebsite = true;
231+
break;
232+
}
233+
}
234+
if (count($websitesList) === 1 && !$defaultSelectedWebsite) {
235+
$website = reset($websitesList);
236+
$children[$website['id']]['arguments']['data']['config']['value'] = (string)$website['id'];
237+
}
214238
return $children;
215239
}
216240

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,7 @@ protected function _saveProducts()
17261726
}
17271727

17281728
$rowData[self::COL_MEDIA_IMAGE] = [];
1729+
list($rowImages, $rowData) = $this->clearNoSelectionImages($rowImages, $rowData);
17291730

17301731
/*
17311732
* Note: to avoid problems with undefined sorting, the value of media gallery items positions
@@ -1934,6 +1935,27 @@ protected function _saveProducts()
19341935

19351936
// phpcs:enable
19361937

1938+
/**
1939+
* Clears entries from Image Set and Row Data marked as no_selection
1940+
*
1941+
* @param array $rowImages
1942+
* @param array $rowData
1943+
* @return array
1944+
*/
1945+
private function clearNoSelectionImages($rowImages, $rowData)
1946+
{
1947+
foreach ($rowImages as $column => $columnImages) {
1948+
foreach ($columnImages as $key => $image) {
1949+
if ($image == 'no_selection') {
1950+
unset($rowImages[$column][$key]);
1951+
unset($rowData[$column]);
1952+
}
1953+
}
1954+
}
1955+
1956+
return [$rowImages, $rowData];
1957+
}
1958+
19371959
/**
19381960
* Prepare array with image states (visible or hidden from product page)
19391961
*

app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
* phpcs:disable Magento2.Commenting.ConstantsPHPDocFormatting
1919
* @SuppressWarnings(PHPMD.TooManyFields)
20+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2021
*/
2122
class Downloadable extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
2223
{
@@ -332,7 +333,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
332333
{
333334
$this->rowNum = $rowNum;
334335
$error = false;
335-
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData)) {
336+
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData) && $isNewProduct) {
336337
$this->_entityModel->addRowError(self::ERROR_OPTIONS_NOT_FOUND, $this->rowNum);
337338
$error = true;
338339
}
@@ -888,8 +889,8 @@ protected function uploadDownloadableFiles($fileName, $type = 'links', $renameFi
888889
try {
889890
$uploader = $this->uploaderHelper->getUploader($type, $this->parameters);
890891
if (!$this->uploaderHelper->isFileExist($fileName)) {
891-
$uploader->move($fileName, $renameFileOff);
892-
$fileName = $uploader['file'];
892+
$res = $uploader->move($fileName, $renameFileOff);
893+
$fileName = $res['file'];
893894
}
894895
} catch (\Exception $e) {
895896
$this->_entityModel->addRowError(self::ERROR_MOVE_FILE, $this->rowNum);

0 commit comments

Comments
 (0)