Skip to content

Commit 48cf519

Browse files
committed
Merge remote-tracking branch 'origin/MC-31838' into 2.4-develop-pr19
2 parents 06460bb + 9dbae29 commit 48cf519

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

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

0 commit comments

Comments
 (0)