Skip to content

Commit 58377de

Browse files
author
Roman Lytvynenko
committed
MC-19706: URL rewrite not created upon creating the product
1 parent 0e69989 commit 58377de

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,12 @@ public function getStoreIds()
832832
if (!$this->hasStoreIds()) {
833833
$storeIds = [];
834834
if ($websiteIds = $this->getWebsiteIds()) {
835-
if ($this->_storeManager->isSingleStoreMode() && !$this->isObjectNew()) {
835+
if (!$this->isObjectNew() && $this->_storeManager->isSingleStoreMode()) {
836836
$websiteIds = array_keys($websiteIds);
837837
}
838838
foreach ($websiteIds as $websiteId) {
839839
$websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
840-
$storeIds = array_merge($storeIds, $websiteStores);
840+
$storeIds = $storeIds + $websiteStores;
841841
}
842842
}
843843
$this->setStoreIds($storeIds);
@@ -920,9 +920,9 @@ public function beforeSave()
920920
//Validate changing of design.
921921
$userType = $this->getUserContext()->getUserType();
922922
if ((
923-
$userType === UserContextInterface::USER_TYPE_ADMIN
923+
$userType === UserContextInterface::USER_TYPE_ADMIN
924924
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
925-
)
925+
)
926926
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
927927
) {
928928
$this->setData('custom_design', $this->getOrigData('custom_design'));

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

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Api\ExtensibleDataInterface;
1414
use Magento\Framework\Api\ExtensionAttributesFactory;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
1819
* Product Test
@@ -207,6 +208,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase
207208
*/
208209
private $eavConfig;
209210

211+
/**
212+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
213+
*/
214+
private $storeManager;
215+
210216
/**
211217
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
212218
*/
@@ -303,13 +309,13 @@ protected function setUp()
303309
->disableOriginalConstructor()
304310
->getMock();
305311

306-
$storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
312+
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
307313
->disableOriginalConstructor()
308314
->getMockForAbstractClass();
309-
$storeManager->expects($this->any())
315+
$this->storeManager->expects($this->any())
310316
->method('getStore')
311317
->will($this->returnValue($this->store));
312-
$storeManager->expects($this->any())
318+
$this->storeManager->expects($this->any())
313319
->method('getWebsite')
314320
->will($this->returnValue($this->website));
315321
$this->indexerRegistryMock = $this->createPartialMock(
@@ -394,7 +400,7 @@ protected function setUp()
394400
'extensionFactory' => $this->extensionAttributesFactory,
395401
'productPriceIndexerProcessor' => $this->productPriceProcessor,
396402
'catalogProductOptionFactory' => $optionFactory,
397-
'storeManager' => $storeManager,
403+
'storeManager' => $this->storeManager,
398404
'resource' => $this->resource,
399405
'registry' => $this->registry,
400406
'moduleManager' => $this->moduleManager,
@@ -450,6 +456,46 @@ public function testGetStoreIds()
450456
$this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
451457
}
452458

459+
/**
460+
* @dataProvider getSingleStoreIds
461+
* @param bool $isObjectNew
462+
*/
463+
public function testGetStoreSingleSiteModelIds(
464+
bool $isObjectNew
465+
) {
466+
$websiteIDs = [0 => 2];
467+
$this->model->setWebsiteIds(
468+
!$isObjectNew ? $websiteIDs : array_flip($websiteIDs)
469+
);
470+
471+
$this->model->isObjectNew($isObjectNew);
472+
473+
$this->storeManager->expects($this->exactly(
474+
(int) !$isObjectNew
475+
))
476+
->method('isSingleStoreMode')
477+
->will($this->returnValue(true));
478+
479+
$this->website->expects(
480+
$this->once()
481+
)->method('getStoreIds')
482+
->will($this->returnValue($websiteIDs));
483+
484+
$this->assertEquals($websiteIDs, $this->model->getStoreIds());
485+
}
486+
487+
public function getSingleStoreIds()
488+
{
489+
return [
490+
[
491+
false
492+
],
493+
[
494+
true
495+
],
496+
];
497+
}
498+
453499
public function testGetStoreId()
454500
{
455501
$this->model->setStoreId(3);
@@ -1221,8 +1267,7 @@ public function testGetMediaGalleryImagesMerging()
12211267
{
12221268
$mediaEntries =
12231269
[
1224-
'images' =>
1225-
[
1270+
'images' => [
12261271
[
12271272
'value_id' => 1,
12281273
'file' => 'imageFile.jpg',

0 commit comments

Comments
 (0)