diff --git a/reversio.zip b/reversio.zip new file mode 100644 index 0000000..b61817a Binary files /dev/null and b/reversio.zip differ diff --git a/reversio/controllers/admin/AdminReversIOAjaxController.php b/reversio/controllers/admin/AdminReversIOAjaxController.php index 6726523..a99f07d 100755 --- a/reversio/controllers/admin/AdminReversIOAjaxController.php +++ b/reversio/controllers/admin/AdminReversIOAjaxController.php @@ -102,6 +102,43 @@ public function ajaxProcessImportOrderToReversIo() } } + public function ajaxProcessDisplayCategories() + { + /** @var \ReversIO\Services\CategoryMapService $categoryMapService */ + /** @var \ReversIO\Services\APIConnect\ReversIOApi $reversIOAPIConnect */ + /** @var \ReversIO\Repository\CategoryMapRepository $categoryMapRepository */ + $categoryMapService = $this->module->getContainer()->get('categoryMapService'); + $reversIOAPIConnect = $this->module->getContainer()->get('reversIoApiConnect'); + $categoryMapRepository = $this->module->getContainer()->get('categoryMapRepository'); + + $buildedChildrens = []; + $childrens = Category::getChildren(Tools::getValue('categoryId'), $this->context->language->id); + foreach ($childrens as $children) { + $buildedChildrens[] = $categoryMapService->getChildrenCategory($children, $this->context->language->id, $categoryMapRepository->getAllMappedCategories()); + } + + $modelTypesList = $reversIOAPIConnect->getModelTypes($this->context->language->iso_code); + + if ($modelTypesList) { + $modelTypesList = $categoryMapService->formatModelTypes($modelTypesList->getContent()['value']); + } + + $tplVars = [ + 'category' => $buildedChildrens, + 'modelTypesList' => $modelTypesList, + 'rootCategory' => $categoryMapService->getRootCategory($this->context->language->id, $this->context->shop, $categoryMapRepository->getAllMappedCategories()), + 'current' => Tools::getValue('current'), + ]; + + $this->context->smarty->assign($tplVars); + + echo $this->context->smarty->fetch( + $this->module->getLocalPath().'views/templates/admin/partials/children.tpl' + ); + + die(); + } + private function updateValues($orderStatus, $orderDateFrom, $orderDateTo) { Configuration::updateValue( diff --git a/reversio/controllers/admin/AdminReversIOCategoryMappingController.php b/reversio/controllers/admin/AdminReversIOCategoryMappingController.php index 45184c7..4dc7965 100755 --- a/reversio/controllers/admin/AdminReversIOCategoryMappingController.php +++ b/reversio/controllers/admin/AdminReversIOCategoryMappingController.php @@ -45,8 +45,12 @@ public function setMedia() { parent::setMedia(); + Media::addJsDef(array( + 'categoryDisplayAjax' => $this->context->link->getAdminLink(\ReversIO\Config\Config::CONTROLLER_ADMIN_AJAX), + )); + $this->addCSS($this->module->getLocalPath() . '/views/css/admin/category-mapping.css'); - $this->addJS($this->module->getLocalPath() . '/views/js/admin/category-mapping.js'); + $this->addJS($this->module->getLocalPath() . '/views/js/admin/category-map.js'); } public function initContent() @@ -110,6 +114,8 @@ private function initCategoryMappingContent() $reversIOAPIConnect = $this->module->getContainer()->get('reversIoApiConnect'); $categoryMapRepository = $this->module->getContainer()->get('categoryMapRepository'); + $rootCategory = $categoryMapService->getRootCategory($this->context->language->id, $this->context->shop, $categoryMapRepository->getAllMappedCategories()); + $categoryTree = $categoryMapService->getMappedCategoryTree( $this->context->language->id, $this->context->shop, @@ -125,6 +131,8 @@ private function initCategoryMappingContent() $tplVars = [ 'categoryTree' => $categoryTree, 'modelTypesList' => $modelTypesList, + 'rootCategory' => $rootCategory, + 'key' => 0, ]; $this->context->smarty->assign($tplVars); diff --git a/reversio/src/Services/CategoryMapService.php b/reversio/src/Services/CategoryMapService.php index 77ac0b9..98d70fe 100755 --- a/reversio/src/Services/CategoryMapService.php +++ b/reversio/src/Services/CategoryMapService.php @@ -57,6 +57,48 @@ public function getMappedCategoryTree($idLang, $shop, $mappedCategories) return $categoryTree; } + public function getRootCategory($idLang, $shop, $mappedCategories) + { + $category = Category::getRootCategory($idLang, $shop); + + $children = Category::getChildren($category->id, $idLang); + + $rootCategoryArray = [ + 'id_category' => $category->id, + 'name' => $category->name, + 'link_rewrite' => $category->link_rewrite, + 'modelType' => isset($mappedCategories[$category->id]) ? + $mappedCategories[$category->id] : + 0 + ]; + + if (isset($children)) { + $rootCategoryArray['children'] = true; + } + + return $rootCategoryArray; + } + + public function getChildrenCategory($category, $idLang, $mappedCategories) + { + $children = Category::getChildren($category['id_category'], $idLang); + + $rootCategoryArray = [ + 'id_category' => $category['id_category'], + 'name' => $category['name'], + 'link_rewrite' => $category['link_rewrite'], + 'modelType' => isset($mappedCategories[$category['id_category']]) ? + $mappedCategories[$category['id_category']] : + 0 + ]; + + if (!empty($children)) { + $rootCategoryArray['children'] = true; + } + + return $rootCategoryArray; + } + public function formatModelTypes($modelTypes) { $formatedModelTyped = []; diff --git a/reversio/vendor/autoload.php b/reversio/vendor/autoload.php index 44566e0..14d0ace 100755 --- a/reversio/vendor/autoload.php +++ b/reversio/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2::getLoader(); +return ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5::getLoader(); diff --git a/reversio/vendor/composer/autoload_real.php b/reversio/vendor/composer/autoload_real.php index 4390415..45dceaa 100755 --- a/reversio/vendor/composer/autoload_real.php +++ b/reversio/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2 +class ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5 { private static $loader; @@ -22,15 +22,15 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2', 'loadClassLoader'), true, false); + spl_autoload_register(array('ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5', 'loadClassLoader'), true, false); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -51,19 +51,19 @@ public static function getLoader() $loader->register(false); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire6db82d6cd26c7148ec88c5adf84f63d2($fileIdentifier, $file); + composerRequire1d9bd9f454a33df47bb157a05f519cd5($fileIdentifier, $file); } return $loader; } } -function composerRequire6db82d6cd26c7148ec88c5adf84f63d2($fileIdentifier, $file) +function composerRequire1d9bd9f454a33df47bb157a05f519cd5($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/reversio/vendor/composer/autoload_static.php b/reversio/vendor/composer/autoload_static.php index 1c45537..992d593 100755 --- a/reversio/vendor/composer/autoload_static.php +++ b/reversio/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2 +class ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5 { public static $files = array ( '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', @@ -108,9 +108,9 @@ class ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5::$classMap; }, null, ClassLoader::class); } diff --git a/reversio/views/js/admin/category-map.js b/reversio/views/js/admin/category-map.js new file mode 100644 index 0000000..c5e5dba --- /dev/null +++ b/reversio/views/js/admin/category-map.js @@ -0,0 +1,88 @@ +/* + *Copyright (c) 2019 Revers.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author revers.io + * @copyright Copyright (c) permanent, Revers.io + * @license Revers.io + * @see /LICENSE + */ + +$(document).ready(function () { + $('body').on('click', '.js-accordion-toggle.accordion-toggle.category-map-heading.collapsed', displayCategories); + $('body').on('click', '.js-accordion-toggle.accordion-toggle.category-map-heading.do-collapsed', hideCategories); + $('body').on('click', '.js-accordion-toggle.accordion-toggle.category-map-heading.collapsed-again', displayHideCategories); + + function displayCategories() { + var $category = $(this); + + var categoryId = $category.attr('data-category-id'); + + $.ajax(categoryDisplayAjax, { + method: 'POST', + data: { + action: 'displayCategories', + ajax: 1, + categoryId: categoryId, + current: currentIndex, + token_bo: token_bo, + }, + success: function (response) { + $('.reversio-category-childrens-'+categoryId).html(response); + $category.addClass('do-collapsed'); + $('.model-list-select.chosen').each(function(k, item){ + $(item).chosen({disable_search_threshold: 10, search_contains: true, width: '100%', }); + }); + }, + error: function (response) { + } + }); + } + + function hideCategories() { + var $category = $(this); + + var categoryId = $category.attr('data-category-id'); + $('.reversio-category-childrens-'+categoryId).hide(); + $category.removeClass('do-collapsed'); + childNodes = $category[0].childNodes; + for (var i = 0; i < childNodes.length; i++) { + if (childNodes[i].nodeType !== 3) { + childNodes[i].className = "icon-circle-arrow-right"; + } + } + $category.addClass('collapsed-again'); + } + + function displayHideCategories() { + var $category = $(this); + + var categoryId = $category.attr('data-category-id'); + $('.reversio-category-childrens-'+categoryId).show(); + $category.removeClass('collapsed collapsed-again'); + childNodes = $category[0].childNodes; + for (var i = 0; i < childNodes.length; i++) { + if (childNodes[i].nodeType !== 3) { + childNodes[i].className = "icon-circle-arrow-down"; + } + } + $category.addClass('do-collapsed'); + } +}); diff --git a/reversio/views/templates/admin/category-mapping-block.tpl b/reversio/views/templates/admin/category-mapping-block.tpl index 40110fe..e59466a 100755 --- a/reversio/views/templates/admin/category-mapping-block.tpl +++ b/reversio/views/templates/admin/category-mapping-block.tpl @@ -42,9 +42,7 @@