Skip to content

Commit 8667ece

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-52737' into Troll-PR
2 parents c95f1cd + dfc68f9 commit 8667ece

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ protected function _filterCategoryPostData(array $rawData)
8282
$data = $rawData;
8383
// @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
8484
if (isset($data['image']) && is_array($data['image'])) {
85-
$data['image_additional_data'] = $data['image'];
86-
unset($data['image']);
85+
if (!empty($data['image']['delete'])) {
86+
$data['image'] = null;
87+
} else {
88+
if (isset($data['image'][0]['name']) && isset($data['image'][0]['tmp_name'])) {
89+
$data['image'] = $data['image'][0]['name'];
90+
} else {
91+
unset($data['image']);
92+
}
93+
}
8794
}
8895
return $data;
8996
}

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,14 @@ private function getImageUploader()
9494
*/
9595
public function afterSave($object)
9696
{
97-
$value = $object->getData($this->getAttribute()->getName() . '_additional_data');
97+
$image = $object->getData($this->getAttribute()->getName(), null);
9898

99-
if (is_array($value) && !empty($value['delete'])) {
100-
$object->setData($this->getAttribute()->getName(), '');
101-
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
102-
return $this;
103-
}
104-
105-
if (isset($value[0]['name']) && isset($value[0]['tmp_name'])) {
99+
if ($image !== null) {
106100
try {
107-
$result = $this->getImageUploader()->moveFileFromTmp($value[0]['name']);
108-
109-
$object->setData($this->getAttribute()->getName(), $result);
110-
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
101+
$this->getImageUploader()->moveFileFromTmp($image);
111102
} catch (\Exception $e) {
112103
$this->_logger->critical($e);
113104
}
114-
} elseif (isset($value[0]['name'])) {
115-
$object->setData($this->getAttribute()->getName(), $value[0]['name']);
116-
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
117105
}
118106
return $this;
119107
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,15 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
9191
);
9292

9393
if (isset($existingData['image']) && is_array($existingData['image'])) {
94-
$existingData['image_additional_data'] = $existingData['image'];
95-
unset($existingData['image']);
94+
if (!empty($existingData['image']['delete'])) {
95+
$existingData['image'] = null;
96+
} else {
97+
if (isset($existingData['image'][0]['name']) && isset($existingData['image'][0]['tmp_name'])) {
98+
$existingData['image'] = $existingData['image'][0]['name'];
99+
} else {
100+
unset($existingData['image']);
101+
}
102+
}
96103
}
97104
} else {
98105
$parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId();

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public function testExecute($categoryId, $storeId, $parentId)
433433
->method('getPostValue')
434434
->willReturn($postData);
435435
$addData = $postData;
436-
$addData['image_additional_data'] = ['delete' => true];
436+
$addData['image'] = ['delete' => true];
437437
$categoryMock->expects($this->once())
438438
->method('addData')
439439
->with($addData);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ public function filterExtraFieldsOnUpdateCategoryDataProvider()
173173
['level' => '1', 'path' => '1/2', 'image' => ['categoryImage'], 'name' => 'category'],
174174
[
175175
'store_id' => 1,
176-
'image_additional_data' => ['categoryImage'],
177176
'name' => 'category',
178177
'entity_id' => null
179178
]

0 commit comments

Comments
 (0)