Skip to content

Commit 6d32161

Browse files
authored
Merge pull request #126 from norgeindian/patch-1
Add category_path_seperator getter
2 parents 5ed6335 + 9399d12 commit 6d32161

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

Model/Config.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class Config extends AbstractHelper
1717
private const XML_PATH_VALIDATION_STRATEGY = 'fastsimpleimport/default/validation_strategy';
1818
private const XML_PATH_ALLOWED_ERROR_COUNT = 'fastsimpleimport/default/allowed_error_count';
1919
private const XML_PATH_IMPORT_IMAGES_FILE_FIR = 'fastsimpleimport/default/import_images_file_dir';
20-
21-
public const XML_PATH_CATEGORY_PATH_SEPERATOR = 'fastsimpleimport/default/category_path_seperator';
20+
private const XML_PATH_CATEGORY_PATH_SEPERATOR = 'fastsimpleimport/default/category_path_seperator';
2221

2322
public function __construct(
2423
Context $context
@@ -55,4 +54,9 @@ public function getImportFileDir(): string
5554
{
5655
return $this->scopeConfig->getValue(self::XML_PATH_IMPORT_IMAGES_FILE_FIR);
5756
}
57+
58+
public function getCategoryPathSeparator(): string
59+
{
60+
return $this->scopeConfig->getValue(self::XML_PATH_CATEGORY_PATH_SEPERATOR);
61+
}
5862
}

Model/Import/Category.php

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class Category extends \Magento\ImportExport\Model\Import\AbstractEntity
216216
private CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator;
217217
private UrlPersistInterface $urlPersist;
218218
private CategoryRepositoryInterface $categoryRepository;
219+
private Config $config;
219220

220221
public function __construct(
221222
StringUtils $string,
@@ -239,6 +240,7 @@ public function __construct(
239240
CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator,
240241
CategoryRepositoryInterface $categoryRepository,
241242
UrlPersistInterface $urlPersist,
243+
Config $config,
242244
array $data = []
243245
) {
244246
parent::__construct(
@@ -279,8 +281,9 @@ public function __construct(
279281
->initAttributes()
280282
->initAttributeSetId();
281283

282-
$this->entityTable = $this->defaultCategory->getResource()->getEntityTable();
284+
$this->entityTable = $this->defaultCategory->getResource()->getEntityTable();
283285
$this->categoryImportVersionFeature = $this->versionFeatures->create('CategoryImportVersion');
286+
$this->config = $config;
284287
}
285288

286289
/**
@@ -382,10 +385,7 @@ private function initCategories(): self
382385
$this->categoriesWithRoots[$rootCategoryName] = [];
383386
}
384387

385-
$index = $this->implodeEscaped(
386-
(string) $this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR),
387-
$path
388-
);
388+
$index = $this->implodeEscaped($this->config->getCategoryPathSeparator(), $path);
389389
$this->categoriesWithRoots[$rootCategoryName][$index] = [
390390
'entity_id' => $category->getId(),
391391
CategoryInterface::KEY_PATH => $category->getData(CategoryInterface::KEY_PATH),
@@ -417,10 +417,7 @@ private function implodeEscaped(string $glue, array $array): string
417417
foreach ($array as $value) {
418418
$newArray[] = str_replace($glue, '\\' . $glue, $value);
419419
}
420-
return implode(
421-
$this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR),
422-
$newArray
423-
);
420+
return implode($this->config->getCategoryPathSeparator(), $newArray);
424421
}
425422

426423
/**
@@ -861,10 +858,7 @@ private function getCategoryName(array $rowData): string
861858
return $rowData[CategoryModel::KEY_NAME];
862859
}
863860

864-
$categoryParts = $this->explodeEscaped(
865-
(string) $this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR),
866-
$rowData[self::COL_CATEGORY]
867-
);
861+
$categoryParts = $this->explodeEscaped($this->config->getCategoryPathSeparator(), $rowData[self::COL_CATEGORY]);
868862
return end($categoryParts);
869863
}
870864

@@ -911,15 +905,10 @@ protected function getParentCategory(array $rowData)
911905
);
912906
$parent = $categoryParts[count($categoryParts) - 2];
913907
} else {
914-
$categoryParts = $this->explodeEscaped(
915-
(string) $this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR),
916-
$rowData[self::COL_CATEGORY]
917-
);
908+
$categoryParts = $this->explodeEscaped($this->config->getCategoryPathSeparator(),
909+
$rowData[self::COL_CATEGORY]);
918910
array_pop($categoryParts);
919-
$parent = $this->implodeEscaped(
920-
(string) $this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR),
921-
$categoryParts
922-
);
911+
$parent = $this->implodeEscaped($this->config->getCategoryPathSeparator(), $categoryParts);
923912
}
924913

925914
if ($parent) {

0 commit comments

Comments
 (0)