From 25111f0dcd1ecf050112647930accd057b2d901a Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Fri, 18 Sep 2020 21:19:28 +0300 Subject: [PATCH] refactoring --- .../Catalog/Model/CategoryRepository.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/CategoryRepository.php b/app/code/Magento/Catalog/Model/CategoryRepository.php index 6865798052e58..0d0ceec6221f7 100644 --- a/app/code/Magento/Catalog/Model/CategoryRepository.php +++ b/app/code/Magento/Catalog/Model/CategoryRepository.php @@ -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( @@ -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; + } }