Skip to content

Commit

Permalink
✨ let the path seperator be configurable for import _category
Browse files Browse the repository at this point in the history
  • Loading branch information
rosenberger-e-conomix committed Sep 12, 2017
1 parent 9943113 commit fc1d5c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Helper/Config.php
Expand Up @@ -16,6 +16,7 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper
const XML_PATH_VALIDATION_STRATEGY = 'fastsimpleimport/default/validation_strategy';
const XML_PATH_ALLOWED_ERROR_COUNT = 'fastsimpleimport/default/allowed_error_count';
const XML_PATH_IMPORT_IMAGES_FILE_FIR = 'fastsimpleimport/default/import_images_file_dir';
const XML_PATH_CATEGORY_PATH_SEPERATOR = 'fastsimpleimport/default/category_path_seperator';

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

public function getCategoryPathSeperator() {
return $this->scopeConfig->getValue(self::XML_PATH_CATEGORY_PATH_SEPERATOR, ScopeInterface::SCOPE_STORE);
}

/**
* @return string
*/
Expand Down
13 changes: 7 additions & 6 deletions Model/Import/Category.php
Expand Up @@ -516,7 +516,7 @@ protected function initCategories()
$this->categoriesWithRoots[$rootCategoryName] = [];
}

$index = $this->implodeEscaped('/', $path);
$index = $this->implodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $path);
$this->categoriesWithRoots[$rootCategoryName][$index] = [
'entity_id' => $category->getId(),
CategoryModel::KEY_PATH => $category->getData(CategoryModel::KEY_PATH),
Expand Down Expand Up @@ -557,7 +557,7 @@ protected function implodeEscaped($glue, array $array)
foreach ($array as $value) {
$newArray[] = str_replace($glue, '\\' . $glue, $value);
}
return implode('/', $newArray);
return implode($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $newArray);
}

/**
Expand Down Expand Up @@ -805,8 +805,9 @@ protected function reindexUpdatedCategories($categoryId)
if ($storeId == 0) {
continue;
}

$category = $this->categoryRepository->get($categoryId, $storeId);
//$category->setStoreId($storeId);

$urlRewrites = $this->categoryUrlRewriteGenerator->generate($category, true);
$this->urlPersist->replace($urlRewrites);
}
Expand Down Expand Up @@ -1052,7 +1053,7 @@ protected function getCategoryName($rowData)
return $rowData[CategoryModel::KEY_NAME];
}

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

Expand Down Expand Up @@ -1094,9 +1095,9 @@ protected function getParentCategory($rowData)
// if _category eq. name then we don't have parents
$parent = false;
} else {
$categoryParts = $this->explodeEscaped('/', $rowData[self::COL_CATEGORY]);
$categoryParts = $this->explodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $rowData[self::COL_CATEGORY]);
array_pop($categoryParts);
$parent = $this->implodeEscaped('/', $categoryParts);
$parent = $this->implodeEscaped($this->_scopeConfig->getValue(Config::XML_PATH_CATEGORY_PATH_SEPERATOR), $categoryParts);
}

if ($parent) {
Expand Down
1 change: 1 addition & 0 deletions Model/Importer.php
Expand Up @@ -69,6 +69,7 @@ public function __construct(
'validation_strategy' => $this->configHelper->getValidationStrategy(),
'allowed_error_count' => $this->configHelper->getAllowedErrorCount(),
'import_images_file_dir' => $this->configHelper->getImportFileDir(),
'category_path_seperator' => $this->configHelper->getCategoryPathSeperator(),
'_import_multiple_value_separator' => Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
];
}
Expand Down
3 changes: 3 additions & 0 deletions etc/adminhtml/system.xml
Expand Up @@ -36,6 +36,9 @@
<label>Ignore duplicates</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="category_path_seperator" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Category path seperator</label>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Expand Up @@ -14,6 +14,7 @@
<entity>catalog_product</entity>
<validation_strategy>validation-stop-on-errors</validation_strategy>
<allowed_error_count>10</allowed_error_count>
<category_path_seperator>/</category_path_seperator>
</default>
</fastsimpleimport>
<system>
Expand Down

0 comments on commit fc1d5c2

Please sign in to comment.