@@ -320,6 +320,44 @@ public function testDeleteChildren()
320
320
$ this ->assertEquals ($ this ->_model ->getId (), null );
321
321
}
322
322
323
+ /**
324
+ * @magentoDataFixture Magento/Store/_files/second_store.php
325
+ * @magentoDataFixture Magento/Catalog/_files/categories.php
326
+ * @magentoDbIsolation enabled
327
+ */
328
+ public function testCreateSubcategoryWithMultipleStores ()
329
+ {
330
+ $ parentCategoryId = 3 ;
331
+ $ storeManager = $ this ->objectManager ->get (\Magento \Store \Model \StoreManagerInterface::class);
332
+ $ storeManager ->setCurrentStore (\Magento \Store \Model \Store::ADMIN_CODE );
333
+ /** @var \Magento\Store\Api\StoreRepositoryInterface $storeRepository */
334
+ $ storeRepository = $ this ->objectManager ->get (\Magento \Store \Api \StoreRepositoryInterface::class);
335
+ $ storeId = $ storeRepository ->get ('fixture_second_store ' )->getId ();
336
+ /** @var \Magento\Catalog\Api\CategoryRepositoryInterface $repository */
337
+ $ repository = $ this ->objectManager ->get (\Magento \Catalog \Api \CategoryRepositoryInterface::class);
338
+ $ parentCategory = $ repository ->get ($ parentCategoryId , $ storeId );
339
+ $ parentAllStoresPath = $ parentCategory ->getUrlPath ();
340
+ $ parentSecondStoreKey = 'parent-category-url-key-second-store ' ;
341
+ $ parentCategory ->setUrlKey ($ parentSecondStoreKey );
342
+ $ repository ->save ($ parentCategory );
343
+ /** @var \Magento\Catalog\Model\Category $childCategory */
344
+ $ childCategory = $ this ->objectManager ->create (\Magento \Catalog \Model \Category::class);
345
+ $ childCategory ->setName ('Test Category 100 ' )
346
+ ->setParentId ($ parentCategoryId )
347
+ ->setLevel (2 )
348
+ ->setAvailableSortBy (['position ' , 'name ' ])
349
+ ->setDefaultSortBy ('name ' )
350
+ ->setIsActive (true )
351
+ ->setPosition (1 )
352
+ ->isObjectNew (true );
353
+ $ repository ->save ($ childCategory );
354
+ $ childCategorySecondStore = $ repository ->get ($ childCategory ->getId (), $ storeId );
355
+
356
+ $ this ->assertEquals ($ parentAllStoresPath . '/test-category-100 ' , $ childCategory ->getUrlPath ());
357
+ $ this ->assertEquals ($ parentSecondStoreKey . '/test-category-100 ' , $ childCategorySecondStore ->getUrlPath ());
358
+
359
+ }
360
+
323
361
protected function getCategoryByName ($ categoryName )
324
362
{
325
363
/* @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
0 commit comments