Skip to content

Commit

Permalink
Add support of partial category mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
juju-revers-io committed Oct 26, 2020
1 parent f14f6ab commit 7f0bd0f
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 26 deletions.
Binary file added reversio.zip
Binary file not shown.
37 changes: 37 additions & 0 deletions reversio/controllers/admin/AdminReversIOAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -125,6 +131,8 @@ private function initCategoryMappingContent()
$tplVars = [
'categoryTree' => $categoryTree,
'modelTypesList' => $modelTypesList,
'rootCategory' => $rootCategory,
'key' => 0,
];

$this->context->smarty->assign($tplVars);
Expand Down
42 changes: 42 additions & 0 deletions reversio/src/Services/CategoryMapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion reversio/vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2::getLoader();
return ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5::getLoader();
14 changes: 7 additions & 7 deletions reversio/vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit6db82d6cd26c7148ec88c5adf84f63d2
class ComposerAutoloaderInit1d9bd9f454a33df47bb157a05f519cd5
{
private static $loader;

Expand All @@ -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) {
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions reversio/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit6db82d6cd26c7148ec88c5adf84f63d2
class ComposerStaticInit1d9bd9f454a33df47bb157a05f519cd5
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
Expand Down Expand Up @@ -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);
}
Expand Down
88 changes: 88 additions & 0 deletions reversio/views/js/admin/category-map.js
Original file line number Diff line number Diff line change
@@ -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');
}
});
4 changes: 1 addition & 3 deletions reversio/views/templates/admin/category-mapping-block.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@

<div class="table-responsive-row clearfix">
<div class="category-map-container accordion js-category-container">
{foreach $categoryTree as $category}
{include file='./partials/category-mapping-part.tpl' category=$category}
{/foreach}
{include file='./partials/category-mapping-part.tpl' category=$rootCategory}
</div>
</div>

Expand Down
13 changes: 3 additions & 10 deletions reversio/views/templates/admin/partials/category-mapping-part.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<div class="accordion-group category-map-part">
<div class="js-accordion-heading accordion-heading heading-container">
<a class="js-accordion-toggle accordion-toggle category-map-heading collapsed" data-toggle="collapse" href="#{$category.link_rewrite|escape:'htmlall':'UTF-8'}">
<a class="js-accordion-toggle accordion-toggle category-map-heading collapsed" data-toggle="collapse" href="#{$category.link_rewrite|escape:'htmlall':'UTF-8'}" data-category-id="{$category.id_category}">
{if isset($category.children)}
<i class="icon-circle-arrow-down"></i>
{/if}
Expand All @@ -44,13 +44,6 @@
</select>
</div>

{if isset($category.children)}
<div id="{$category.link_rewrite|escape:'htmlall':'UTF-8'}" class="js-accordion-body accordion-body collapse no-transition">
<div class="accordion-inner">
{foreach $category.children as $categoryChildren}
{include file='./category-mapping-part.tpl' category=$categoryChildren}
{/foreach}
</div>
</div>
{/if}
<div class="reversio-category-childrens-{$category.id_category}">
</div>
</div>
4 changes: 4 additions & 0 deletions reversio/views/templates/admin/partials/children.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{foreach $category as $categoryChildren}
{include file='./category-mapping-part.tpl' category=$categoryChildren}
{/foreach}
Binary file added reversio1.6.fixed.zip
Binary file not shown.
Binary file added reversio1.6.zip
Binary file not shown.
Binary file added reversio16.zip
Binary file not shown.

0 comments on commit 7f0bd0f

Please sign in to comment.