Skip to content

Commit 78a88a0

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

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ 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 (is_array($data['image']) && !empty($data['image']['delete'])) {
86+
$data['image'] = null;
87+
} else {
88+
$data['image_new_data'] = $data['image'];
89+
unset($data['image']);
90+
}
8791
}
8892
return $data;
8993
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,7 @@ private function getImageUploader()
9494
*/
9595
public function afterSave($object)
9696
{
97-
$value = $object->getData($this->getAttribute()->getName() . '_additional_data');
98-
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-
}
97+
$value = $object->getData($this->getAttribute()->getName() . '_new_data');
10498

10599
if (isset($value[0]['name']) && isset($value[0]['tmp_name'])) {
106100
try {
@@ -111,9 +105,6 @@ public function afterSave($object)
111105
} catch (\Exception $e) {
112106
$this->_logger->critical($e);
113107
}
114-
} elseif (isset($value[0]['name'])) {
115-
$object->setData($this->getAttribute()->getName(), $value[0]['name']);
116-
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
117108
}
118109
return $this;
119110
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ 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 (is_array($existingData['image']) && !empty($existingData['image']['delete'])) {
95+
$existingData['image'] = null;
96+
} else {
97+
$existingData['image_new_data'] = $existingData['image'];
98+
unset($existingData['image']);
99+
}
96100
}
97101
} else {
98102
$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_new_data'] = ['delete' => true];
437437
$categoryMock->expects($this->once())
438438
->method('addData')
439439
->with($addData);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function filterExtraFieldsOnUpdateCategoryDataProvider()
173173
['level' => '1', 'path' => '1/2', 'image' => ['categoryImage'], 'name' => 'category'],
174174
[
175175
'store_id' => 1,
176-
'image_additional_data' => ['categoryImage'],
176+
'image_new_data' => ['categoryImage'],
177177
'name' => 'category',
178178
'entity_id' => null
179179
]

0 commit comments

Comments
 (0)