Skip to content

Commit f7eec04

Browse files
committed
MAGETWO-52737: Deleting category's image on custom store view - deletes category's images for all store views
1 parent 78a88a0 commit f7eec04

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ protected function _filterCategoryPostData(array $rawData)
8585
if (is_array($data['image']) && !empty($data['image']['delete'])) {
8686
$data['image'] = null;
8787
} else {
88-
$data['image_new_data'] = $data['image'];
89-
unset($data['image']);
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+
}
9093
}
9194
}
9295
return $data;

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

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

99-
if (isset($value[0]['name']) && isset($value[0]['tmp_name'])) {
99+
if ($image !== null) {
100100
try {
101-
$result = $this->getImageUploader()->moveFileFromTmp($value[0]['name']);
102-
103-
$object->setData($this->getAttribute()->getName(), $result);
104-
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
101+
$this->getImageUploader()->moveFileFromTmp($image);
105102
} catch (\Exception $e) {
106103
$this->_logger->critical($e);
107104
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
9494
if (is_array($existingData['image']) && !empty($existingData['image']['delete'])) {
9595
$existingData['image'] = null;
9696
} else {
97-
$existingData['image_new_data'] = $existingData['image'];
98-
unset($existingData['image']);
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+
}
99102
}
100103
}
101104
} else {

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_new_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_new_data' => ['categoryImage'],
177176
'name' => 'category',
178177
'entity_id' => null
179178
]

0 commit comments

Comments
 (0)