Skip to content

Commit 25111f0

Browse files
committed
refactoring
1 parent f61a27a commit 25111f0

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ public function __construct(
7777
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
7878
{
7979
$storeId = (int)$this->storeManager->getStore()->getId();
80-
$existingData = $this->getExtensibleDataObjectConverter()
81-
->toNestedArray($category, [], \Magento\Catalog\Api\Data\CategoryInterface::class);
82-
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
83-
$existingData['store_id'] = $storeId;
84-
85-
if (is_array($category->getData())) {
86-
$existingData = array_replace($existingData, $category->getData());
87-
}
80+
$existingData = $this->getExistingData($category, $storeId);
8881

8982
if ($category->getId()) {
9083
$metadata = $this->getMetadataPool()->getMetadata(
@@ -243,4 +236,25 @@ private function getMetadataPool()
243236
}
244237
return $this->metadataPool;
245238
}
239+
240+
/**
241+
* Get existing data category
242+
*
243+
* @param CategoryInterface $category
244+
* @param int $storeId
245+
* @return array
246+
*/
247+
private function getExistingData(CategoryInterface $category, int $storeId)
248+
{
249+
$existingData = $this->getExtensibleDataObjectConverter()
250+
->toNestedArray($category, [], \Magento\Catalog\Api\Data\CategoryInterface::class);
251+
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
252+
$existingData['store_id'] = $storeId;
253+
254+
if (is_array($category->getData())) {
255+
$existingData = array_replace($existingData, $category->getData());
256+
}
257+
258+
return $existingData;
259+
}
246260
}

0 commit comments

Comments
 (0)