Hallo Zusammen,
ich habe ein Problem bei meinem Plugin und komme einfach nicht weiter. Den Shop habe ich jetzt von 5.2.4 auf 5.3.2 geupdated. Jetzt funktioniert allerdings mein Plugin nicht mehr und ich kann mir nicht erklären warum.
Der Fehler der im Frontend ausgespuckt wird lautet:
Syntax error in template "file:/var/www/vhosts/testsystem.xxx.de/httpdocs/templates/eigenesTemplate/boxes/box_filter_characteristics.tpl" on line 6 "{filter_group_and_sort_adjust_sort_of_jtl_filter}" unknown tag 'filter_group_and_sort_adjust_sort_of_jtl_filter
Hat jemand eine Ahnung, warum, wieso, weshalb das jetzt auf einmal nicht mehr funktioniert. Hätte gedacht, dass das innerhalb einer Major-Version kein Problem sein dürfte.
Vielen Dank im Vorraus
ich habe ein Problem bei meinem Plugin und komme einfach nicht weiter. Den Shop habe ich jetzt von 5.2.4 auf 5.3.2 geupdated. Jetzt funktioniert allerdings mein Plugin nicht mehr und ich kann mir nicht erklären warum.
Der Fehler der im Frontend ausgespuckt wird lautet:
Syntax error in template "file:/var/www/vhosts/testsystem.xxx.de/httpdocs/templates/eigenesTemplate/boxes/box_filter_characteristics.tpl" on line 6 "{filter_group_and_sort_adjust_sort_of_jtl_filter}" unknown tag 'filter_group_and_sort_adjust_sort_of_jtl_filter
Code:
{block name='boxes-box-filter-characteristics'}
{if $nSeitenTyp === $smarty.const.PAGE_ARTIKELLISTE
&& !($isMobile || $Einstellungen.template.productlist.filter_placement === 'modal')}
{filter_group_and_sort_adjust_sort_of_jtl_filter assign='sortedAndGroupedBoxItems' boxItems=$oBox->getItems() ignoreNotDefined=false groupByDefinition=true}
{foreach $sortedAndGroupedBoxItems as $boxItemGroup}
{foreach $boxItemGroup.items as $characteristic}
{if ($characteristic->getData('cTyp') === 'SELECTBOX') && $characteristic->getOptions()|@count > 0}
{if {showMerkmalfilter merkmalname=$characteristic->getName()} && $characteristic->getOptions()|@count > 0}
{assign var="showfilter" value=true}
{/if}
{/if}
{/foreach}
{/foreach}
{if $showfilter}
<h4 class="d-lg-block title_merkmalfilter float-left">{lang key="merkmalfilter_title" section="global"}</h4>
{if $NaviFilter->getURL()->getUnsetAll() !== null}
{block name='snippets-filter-active-filter-remove'}
{link href=$NaviFilter->getURL()->getUnsetAll()
title="{lang key='removeFilters'}"
class='float-right mt-1 text-muted font-weight-bold'}
{lang key='removeFilters'}
{/link}
{/block}
{/if}
{else}
{/if}
{foreach $sortedAndGroupedBoxItems as $boxItemGroup}
{*if ($sortedAndGroupedBoxItems|count <= 1 && $boxItemGroup.name != "unknown group") || $sortedAndGroupedBoxItems|count > 1}
{foreach $boxItemGroup.items as $characteristic}
{if {showMerkmalfilter merkmalname=$characteristic->getName()} && $characteristic->getOptions()|@count > 0}
{assign var="titlevisible" value=true}
{/if}
{/foreach}
{/if*}
{assign var="titlevisible" value=false}
{foreach $boxItemGroup.items as $characteristic}
{if ($characteristic->getData('cTyp') === 'SELECTBOX') && $characteristic->getOptions()|@count > 0}
{if {showMerkmalfilter merkmalname=$characteristic->getName()} && $characteristic->getOptions()|@count > 0}
{assign var="titlevisible" value=true}
{/if}
{/if}
{/foreach}
{if $titlevisible}
<div class="filter-group-title">{if $boxItemGroup.name == "unknown group"}{lang key='miscellaneous'}{else}{lang key=$boxItemGroup.name section="custom"}{/if}</div>
{/if}
{foreach $boxItemGroup.items as $characteristic}
{if ($characteristic->getData('cTyp') === 'SELECTBOX') && $characteristic->getOptions()|@count > 0}
{if {showMerkmalfilter merkmalname=$characteristic->getName()} && $characteristic->getOptions()|@count > 0}
{* Hole Reset Link & Aktuellen Wert *}
{assign var=characteristic_options value=$characteristic->getOptions()}
{assign var=wg_aktueller_filter value=''}
{assign var=wg_unset_url value=''}
{foreach $NaviFilter->getActiveFilters() as $activeFilter}
{assign var=activeFilterValue value=$activeFilter->getValue()}
{assign var=activeValues value=$activeFilter->getActiveValues()}
{if $activeFilterValue !== null}
{if isset($characteristic_options[0])}
{if $characteristic_options[0]->__get('kMerkmalWert') == $activeFilter->__get('kMerkmalWert')}
{* Aktiver Filterwert Name *}
{assign var=wg_aktueller_filter value=$activeValues->getFrontendName()}
{assign var=activeFilterValue value=$activeFilter->getValue()}
{assign var=activeValues value=$activeFilter->getActiveValues()}
{if $activeFilterValue !== null}
{* Reset Link *}
{assign var=wg_unset_url value=$activeFilter->getUnsetFilterURL($activeFilter->getValue())}
{/if}
{/if}
{/if}
{/if}
{/foreach}
{* / Hole Reset Link & Aktuellen Wert *}
<div id="sidebox{$oBox->getID()}-{$characteristic->getID()}" class="box box-filter-characteristics d-lg-block mb-3">
{*button
variant="link"
class="btn-filter-box dropdown-toggle"
role="button"
block=true
data=["toggle"=> "collapse", "target"=>"#cllps-box{$oBox->getID()}-{$characteristic->getID()}"]
}
<span class="characteristic-collapse-btn-inner text-truncate">
{$img = $characteristic->getImage(\JTL\Media\Image::SIZE_XS)}
{if $Einstellungen.navigationsfilter.merkmal_anzeigen_als !== 'T'
&& $img !== null
&& $img|strpos:$smarty.const.BILD_KEIN_MERKMALBILD_VORHANDEN === false
&& $img|strpos:$smarty.const.BILD_KEIN_ARTIKELBILD_VORHANDEN === false}
{include file='snippets/image.tpl'
item=$characteristic
square=false
class='img-xs'
srcSize='xs'
sizes='24px'}
{/if}
{if $Einstellungen.navigationsfilter.merkmal_anzeigen_als !== 'B'}
{$characteristic->getName()|escape:'html'}
{/if}
</span>
{/button*}
{* Hole Merkmalfilter Texte *}
{get_merkmalfilter_beschreibung assign='merkmalfilter_beschreibung' merkmalname=$characteristic->getName()}
{collapse id="cllps-box{$oBox->getID()}-{$characteristic->getID()}" visible=$characteristic->isActive() || $Einstellungen.template.productlist.filter_items_always_visible === 'Y'}
<div class="btn-group btn-block" role="group" aria-label="{$characteristic->getName()|escape:'html'}">
{block name='boxes-box-filter-characteristics-characteristics'}
{if ($characteristic->getData('cTyp') === 'SELECTBOX') && $characteristic->getOptions()|@count > 0}
{block name='boxes-box-filter-characteristics-select'}
{* Merkmalfilter-Name Dropdown Burron *}
<button class="{if $characteristic->isActive()}bg-g1 {/if}btn btn-outline-secondary dropdown-toggle btn-block text-left-util btn-sm font-weight-normal" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{$characteristic->getName()|escape:'html'}{if !empty($wg_aktueller_filter)}: {$wg_aktueller_filter}{/if}
</button>
{* Filter Reset *}
{if $characteristic->isActive()}
<a href="{$wg_unset_url}" class="btn btn-outline-secondary btn-sm ml-1 " aria-expanded="true">
<i class="fas fa-times-circle"></i>
</a>
{/if}
{* Merkmalfilter Werte *}
<div class="dropdown-menu">
{block name='boxes-box-filter-characteristics-include-characteristics-dropdown'}
{include file='snippets/filter/characteristic.tpl' Merkmal=$characteristic}
{/block}
</div>
{* Merkmal Info Button *}
{if $merkmalfilter_beschreibung !== false}
<button type="button" class="btn btn-outline-secondary btn-sm no-toggler collapsed ml-1 merkmal_info" data-toggle="collapse" href="#filter-info-{$oBox->getID()}-{$characteristic->getID()}" role="button" aria-expanded="false" aria-controls="collapseExample">
<img width="20" src="templates/Webgreat_KE/themes/ke/images/icons/ke-info-32.svg">
</button>
{/if}
{/block}
{else}
{*
{block name='boxes-box-filter-characteristics-link'}
{block name='boxes-box-filter-characteristics-include-characteristics-link'}
{include file='snippets/filter/characteristic.tpl' Merkmal=$characteristic}
{/block}
{/block}
*}
{/if}
{/block}
</div> {*/ btn group*}
{if $merkmalfilter_beschreibung !== false}
<div class="collapse" id="filter-info-{$oBox->getID()}-{$characteristic->getID()}">
<div class="p-2 bg-light">
{$merkmalfilter_beschreibung}
</div>
</div>
{/if}
{/collapse}
{block name='boxes-box-filter-characteristics-hr'}
<hr class="border-0 mt-2 mb-2">
{/block}
</div>
{/if} {* END IF cName !== xy *}
{/if} {* END IF SELECTBOX *}
{/foreach}
{/foreach}
{/if}
{/block}
PHP:
<?php
declare(strict_types=1);
namespace Plugin\sm_characteristicFilter\src;
use JTL\Plugin\LegacyPlugin;
use JTL\Plugin\Plugin;
use JTL\Events\Dispatcher;
use Monolog\Logger;
use JTL\Shop;
use Smarty as SmartyCore;
use SmartyException;
/**
* Class Frontend
* @package Plugin\sm_characteristicFilter\src
*
*/
class Frontend
{
/**
* @var LegacyPlugin|Plugin
*/
protected $plugin;
/**
* @var Logger
*/
protected $logger;
/**
* Frontend constructor.
*
* @param LegacyPlugin|Plugin $plugin
* @param Logger $logger
*/
public function __construct($plugin, Logger $logger)
{
$this->plugin = $plugin;
$this->logger = $logger;
}
/**
* Bootup the frontend and registers the required event listeners.
*
* @param Dispatcher $dispatcher
*
* @return void
*
* @throws SmartyException
*/
public function boot(Dispatcher $dispatcher)
{
// No hooks defined to listen to
if (empty(Hooks::LISTEN_TO)) {
return;
}
// Create new hook handler
$hooks = new Hooks($this->plugin, $this->logger);
foreach (Hooks::LISTEN_TO as $hook => $config) {
// Read the config of hook
$method = $config['method'];
$priority = (int) ($config['priority'] ?? 5);
// Method doesn't exists
if (! method_exists($hooks, $method)) {
continue;
}
$dispatcher->listen('shop.hook.' . $hook, [$hooks, $method], $priority);
}
// Create an instance of our smarty plugin
//$plugin = new Smarty();
$plugin = new SmartyCore();
//dump(function_exists('getCharacteristicGroups'));
//dump($plugin);
// Get the smarty instance of shop
Shop::Smarty()
->registerPlugin(SmartyCore::PLUGIN_FUNCTION, 'load_filter_group_and_sort_characteristics', [
$plugin,
'loadFilterGroupAndSortCharacteristics',
])
->registerPlugin(SmartyCore::PLUGIN_FUNCTION, 'filter_group_and_sort_characteristics', [
$plugin,
'filterGroupAndSortCharacteristics',
])
->registerPlugin(SmartyCore::PLUGIN_FUNCTION, 'filter_group_and_sort_property_groups', [
$plugin,
'propertyGroupAndSorts',
])
->registerPlugin(SmartyCore::PLUGIN_FUNCTION, 'filter_group_and_sort_adjust_sort_of_jtl_filter', [
$plugin,
'adjustJTLFilterSort',
])
->registerPlugin(SmartyCore::PLUGIN_FUNCTION, 'get_characteristic_group_definitions', [
$plugin,
'getCharacteristicGroups',
]);
}
}
Code:
/**
* Handle the update of jtl filter characteristic sort.
*
* @param array $params
* @param Smarty_Internal_TemplateBase $smarty
*
* @return void
*/
public function adjustJTLFilterSort(array $params, Smarty_Internal_TemplateBase $smarty): void
{
// We're missing an required param
if (! isset($params['assign'], $params['boxItems'])) {
return;
}
// Load the sort definition
$sortDefinitions = array_map(function (array $item): array
{
$item['characteristic_id'] = (int) $item['characteristic_id'];
$item['item_sort'] = (int) $item['item_sort'];
$item['sort'] = (int) $item['sort'];
$item['enabled'] = (bool) ((int) $item['enabled']);
$item['group_id'] = (int) $item['group_id'];
$item['group_sort'] = (int) $item['group_sort'];
//((`characteristic`.`sort` + 1) * (`group`.`sort` + `group`.`id`)) as `sort`
return $item;
}, Shop::Container()->getDB()->executeQuery('
select
`characteristic`.`characteristic_id`,
((`group`.`sort` + `group`.`id` + 10) + (`characteristic`.`sort` + 15)) as `sort`,
`characteristic`.`enabled`,
`characteristic`.`sort` AS `item_sort`,
`group`.`id` as `group_id`,
`group`.`name` as `group_name`,
`group`.`sort` as `group_sort`
from
`' . CharacteristicSort::TABLE . '` as `characteristic`
join `' . CharacteristicGroup::TABLE . '` as `group` on `group`.`id` = `characteristic`.`group_id`
order by
`group`.`sort`
', DBReturnType::ARRAY_OF_ASSOC_ARRAYS));
// Map the definitions by their id
$sortDefinitionsTmp = [];
foreach ($sortDefinitions as $sortDefinition) {
$sortDefinitionsTmp[$sortDefinition['characteristic_id']] = $sortDefinition;
}
$sortDefinitions = $sortDefinitionsTmp;
unset($sortDefinitionsTmp);
// Handle the sort of box items
$boxItems = (new Collection($params['boxItems']))
->transform(function (Option $option) use (&$sortDefinitions) {
$optionId = $option->getID();
$optionSortDefinitions = [
'characteristic_id' => null,
'sort' => PHP_INT_MAX,
'enabled' => null,
'group_id' => null,
'group_name' => null,
'group_sort' => PHP_INT_MAX - 1,
];
// We have an definition for this characteristic option
if (isset($sortDefinitions[$optionId])) {
$optionSortDefinitions = $sortDefinitions[$optionId];
}
$option->setData('customSort', $optionSortDefinitions['sort']);
$option->setData('customItemSort', $optionSortDefinitions['item_sort']);
$option->setData('isListEnabled', $optionSortDefinitions['enabled']);
$option->setData('customGroup', [
'id' => $optionSortDefinitions['group_id'],
'name' => $optionSortDefinitions['group_name'],
'sort' => $optionSortDefinitions['group_sort'],
]);
return $option;
})
->sortBy(function (Option $option) {
return $option->getData('customSort');
}, SORT_REGULAR, isset($params['descending']) && $params['descending']);
// We should ignore none grouped items?
if (isset($params['ignoreNotDefined']) && $params['ignoreNotDefined']) {
$boxItems = $boxItems->reject(function (Option $option) {
return $option->getData('customGroup')['id'] === null;
});
}
// We want an grouped version as result
if (isset($params['groupByDefinition']) && $params['groupByDefinition']) {
// Group the items by their group definition
$boxItems = $boxItems
->sortBy(function (Option $option) {
return $option->getData('customGroup')['sort'] ?? 0;
})
->groupBy(function (Option $option) {
return $option->getData('customGroup')['name'] ?? 'unknown group';
})
->map(function (Collection $options, string $name) {
return [
'id' => $options->first()->getData('customGroup')['id'] ?? null,
'name' => $name,
'items' => $options
->sortBy(function (Option $option, int $index) {
return $option->getData('customItemSort') ?? $index;
})
->all(),
];
})
->values();
}
$smarty->assign($params['assign'], $boxItems->toArray());
}
PHP:
<?php
declare(strict_types=1);
namespace Plugin\sm_characteristicFilter;
use JTL\Exceptions\CircularReferenceException;
use JTL\Exceptions\ServiceNotFoundException;
use JTL\Plugin\Bootstrapper;
use JTL\Events\Dispatcher;
use JTL\Shop;
use JTL\Smarty\JTLSmarty;
use Plugin\sm_characteristicFilter\Migrations\Migration20201120181500;
use Plugin\sm_characteristicFilter\Migrations\Migration20210206111500;
use Plugin\sm_characteristicFilter\Migrations\Migration20210513082400;
use Plugin\sm_characteristicFilter\src\Frontend;
use Plugin\sm_characteristicFilter\src\Admin;
/**
* Class Bootstrap
* @package Plugin\sm_characteristicFilter
*/
class Bootstrap extends Bootstrapper
{
/**
* Hold the id of ajax request detection.
*
* @var string
*/
const AJAX_REQUEST_ID = 'xxx_characteristics';
/**
* Hold the list of defined migrations to handle at remove.
*
* @var string[]
*/
const MIGRATIONS = [
Migration20201120181500::class,
Migration20210206111500::class,
Migration20210513082400::class,
];
/**
* @var Frontend|null
*/
protected $frontend;
/**
* @var Admin|null
*/
protected $admin;
/**
* Handle the boot of plugin.
*
* @param Dispatcher $dispatcher
*
* @return void
*
* @throws ServiceNotFoundException
* @throws CircularReferenceException
*/
public function boot(Dispatcher $dispatcher)
{
// Handle the parent boot first before do our boot up
parent::boot($dispatcher);
if (Shop::isFrontend()) {
$this->frontend = new Frontend($this->getPlugin(), Shop::Container()->getLogService());
$this->frontend->boot($dispatcher);
return;
}
$this->admin = new Admin($this->getPlugin(), Shop::Container()->getBackendLogService());
}
/**
* Handle the uninstallation of plugin and delete the added database tables if wished.
*
* @param bool $deleteData
*
* @return void
*/
public function uninstalled(bool $deleteData = true)
{
// Handle parent first if there maybe change something in future
parent::uninstalled($deleteData);
// The administrator want to delete the data too
if ($deleteData) {
// Load the database instance to handle remove
$db = Shop::Container()->getDB();
// Step through the migrations and remove the database tables which were added by each migration.
foreach (static::MIGRATIONS as $migrationClass) {
$migration = new $migrationClass($db);
$migration->remove();
}
}
}
/**
* Render the tab and return the content of the rendered tab.
*
* @param string $tabName
* @param int $menuID
* @param JTLSmarty $smarty
*
* @return string
*/
public function renderAdminMenuTab(string $tabName, int $menuID, JTLSmarty $smarty): string
{
// Extend the smarty data
$smarty
->assign('apiUrl', Shop::getURL() . '/index.php?fromAdmin=yes&' . static::AJAX_REQUEST_ID . '=1')
->assign('pluginAdminUrl', $this->getPlugin()->getPaths()->getAdminURL())
->assign('pluginId', $this->getPlugin()->getID())
->assign('tabName', $tabName)
->assign('menuId', $menuID);
// Render the tab
switch ($tabName) {
case 'Merkmal - Gruppen':
return $this->admin->getGroupsTab($smarty);
case 'Eigenschaft - Gruppen':
return $this->admin->getPropertyGroupTab($smarty);
}
// No group was found than handle by parent
return parent::renderAdminMenuTab($tabName, $menuID, $smarty);
}
}
Hat jemand eine Ahnung, warum, wieso, weshalb das jetzt auf einmal nicht mehr funktioniert. Hätte gedacht, dass das innerhalb einer Major-Version kein Problem sein dürfte.
Vielen Dank im Vorraus
Zuletzt bearbeitet: