Skip to content

Commit 76f1395

Browse files
authored
Merge pull request #59 from brosenberger/category_seperator
Category seperator
2 parents 60f2c15 + fc1d5c2 commit 76f1395

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

Helper/Config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper
1616
const XML_PATH_VALIDATION_STRATEGY = 'fastsimpleimport/default/validation_strategy';
1717
const XML_PATH_ALLOWED_ERROR_COUNT = 'fastsimpleimport/default/allowed_error_count';
1818
const XML_PATH_IMPORT_IMAGES_FILE_FIR = 'fastsimpleimport/default/import_images_file_dir';
19+
const XML_PATH_CATEGORY_PATH_SEPERATOR = 'fastsimpleimport/default/category_path_seperator';
1920

2021
/**
2122
* @param \Magento\Framework\App\Helper\Context $context
@@ -26,6 +27,10 @@ public function __construct(
2627
parent::__construct($context);
2728
}
2829

30+
public function getCategoryPathSeperator() {
31+
return $this->scopeConfig->getValue(self::XML_PATH_CATEGORY_PATH_SEPERATOR, ScopeInterface::SCOPE_STORE);
32+
}
33+
2934
/**
3035
* @return string
3136
*/

Model/Import/Category.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ protected function initCategories()
516516
$this->categoriesWithRoots[$rootCategoryName] = [];
517517
}
518518

519-
$index = $this->implodeEscaped('/', $path);
519+
$index = $this->implodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $path);
520520
$this->categoriesWithRoots[$rootCategoryName][$index] = [
521521
'entity_id' => $category->getId(),
522522
CategoryModel::KEY_PATH => $category->getData(CategoryModel::KEY_PATH),
@@ -557,7 +557,7 @@ protected function implodeEscaped($glue, array $array)
557557
foreach ($array as $value) {
558558
$newArray[] = str_replace($glue, '\\' . $glue, $value);
559559
}
560-
return implode('/', $newArray);
560+
return implode($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $newArray);
561561
}
562562

563563
/**
@@ -805,8 +805,9 @@ protected function reindexUpdatedCategories($categoryId)
805805
if ($storeId == 0) {
806806
continue;
807807
}
808+
808809
$category = $this->categoryRepository->get($categoryId, $storeId);
809-
//$category->setStoreId($storeId);
810+
810811
$urlRewrites = $this->categoryUrlRewriteGenerator->generate($category, true);
811812
$this->urlPersist->replace($urlRewrites);
812813
}
@@ -1052,7 +1053,7 @@ protected function getCategoryName($rowData)
10521053
return $rowData[CategoryModel::KEY_NAME];
10531054
}
10541055

1055-
$categoryParts = $this->explodeEscaped('/', $rowData[self::COL_CATEGORY]);
1056+
$categoryParts = $this->explodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $rowData[self::COL_CATEGORY]);
10561057
return end($categoryParts);
10571058
}
10581059

@@ -1094,9 +1095,9 @@ protected function getParentCategory($rowData)
10941095
// if _category eq. name then we don't have parents
10951096
$parent = false;
10961097
} else {
1097-
$categoryParts = $this->explodeEscaped('/', $rowData[self::COL_CATEGORY]);
1098+
$categoryParts = $this->explodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $rowData[self::COL_CATEGORY]);
10981099
array_pop($categoryParts);
1099-
$parent = $this->implodeEscaped('/', $categoryParts);
1100+
$parent = $this->implodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $categoryParts);
11001101
}
11011102

11021103
if ($parent) {

Model/Importer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function __construct(
6969
'validation_strategy' => $this->configHelper->getValidationStrategy(),
7070
'allowed_error_count' => $this->configHelper->getAllowedErrorCount(),
7171
'import_images_file_dir' => $this->configHelper->getImportFileDir(),
72+
'category_path_seperator' => $this->configHelper->getCategoryPathSeperator(),
7273
'_import_multiple_value_separator' => Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
7374
];
7475
}

etc/adminhtml/system.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<label>Ignore duplicates</label>
3737
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
3838
</field>
39+
<field id="category_path_seperator" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="0">
40+
<label>Category path seperator</label>
41+
</field>
3942
</group>
4043
</section>
4144
</system>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<entity>catalog_product</entity>
1515
<validation_strategy>validation-stop-on-errors</validation_strategy>
1616
<allowed_error_count>10</allowed_error_count>
17+
<category_path_seperator>/</category_path_seperator>
1718
</default>
1819
</fastsimpleimport>
1920
<system>

0 commit comments

Comments
 (0)