Skip to content

Commit f11994a

Browse files
Merge forwardport of #11049 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11049.patch (created by @avdb) based on commit(s): 1. c3ea1f5 2. 0c0393d 3. 8660485 Fixed GitHub Issues in 2.3-develop branch: - #10697: Product Import: Additional data: Invalid URL key (reported by @Alex-James17)
2 parents 0fc86d8 + dbe5fc7 commit f11994a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ protected function createCategory($name, $parentId)
119119
$category->setIsActive(true);
120120
$category->setIncludeInMenu(true);
121121
$category->setAttributeSetId($category->getDefaultAttributeSetId());
122-
$category->save();
123-
$this->categoriesCache[$category->getId()] = $category;
122+
try {
123+
$category->save();
124+
$this->categoriesCache[$category->getId()] = $category;
125+
} catch (\Exception $e) {
126+
$this->addFailedCategory($category, $e);
127+
}
124128

125129
return $category->getId();
126130
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/CategoryProcessorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ protected function setUp()
4949
. self::CHILD_CATEGORY_ID
5050
));
5151

52+
$childCategory->method('save')->willThrowException(new \Exception());
53+
5254
$parentCategory = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
5355
->disableOriginalConstructor()
5456
->getMock();
@@ -105,6 +107,17 @@ public function testUpsertCategories()
105107
$this->assertArrayHasKey(self::CHILD_CATEGORY_ID, array_flip($categoryIds));
106108
}
107109

110+
/**
111+
* Tests case when newly created category save throws exception.
112+
*/
113+
public function testCreateCategoryException()
114+
{
115+
$method = new \ReflectionMethod(CategoryProcessor::class, 'createCategory');
116+
$method->setAccessible(true);
117+
$method->invoke($this->categoryProcessor, self::CHILD_CATEGORY_NAME, self::PARENT_CATEGORY_ID);
118+
$this->assertNotEmpty($this->categoryProcessor->getFailedCategories());
119+
}
120+
108121
public function testClearFailedCategories()
109122
{
110123
$dummyFailedCategory = [

0 commit comments

Comments
 (0)