Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Echo committed Sep 18, 2020
1 parent f61a27a commit 25111f0
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions app/code/Magento/Catalog/Model/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ public function __construct(
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
{
$storeId = (int)$this->storeManager->getStore()->getId();
$existingData = $this->getExtensibleDataObjectConverter()
->toNestedArray($category, [], \Magento\Catalog\Api\Data\CategoryInterface::class);
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
$existingData['store_id'] = $storeId;

if (is_array($category->getData())) {
$existingData = array_replace($existingData, $category->getData());
}
$existingData = $this->getExistingData($category, $storeId);

if ($category->getId()) {
$metadata = $this->getMetadataPool()->getMetadata(
Expand Down Expand Up @@ -243,4 +236,25 @@ private function getMetadataPool()
}
return $this->metadataPool;
}

/**
* Get existing data category
*
* @param CategoryInterface $category
* @param int $storeId
* @return array
*/
private function getExistingData(CategoryInterface $category, int $storeId)
{
$existingData = $this->getExtensibleDataObjectConverter()
->toNestedArray($category, [], \Magento\Catalog\Api\Data\CategoryInterface::class);
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
$existingData['store_id'] = $storeId;

if (is_array($category->getData())) {
$existingData = array_replace($existingData, $category->getData());
}

return $existingData;
}
}

0 comments on commit 25111f0

Please sign in to comment.