87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\HannahBundle\Admin\Tabs;
|
|
|
|
use External\HannahBundle\Util\Configuration;
|
|
use KupShop\AdminBundle\Admin\WindowTab;
|
|
|
|
class SettingsOCTab extends WindowTab
|
|
{
|
|
protected $title = 'flapSettingsOutdoor';
|
|
protected $template = 'window/settings.oc.tpl';
|
|
|
|
/** @required */
|
|
public Configuration $configuration;
|
|
|
|
public static function getTypes()
|
|
{
|
|
return [
|
|
'settings' => 0,
|
|
];
|
|
}
|
|
|
|
public function getVars($smarty_tpl_vars)
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
return [
|
|
'variationLabelsMapping' => $dbcfg->outdoorconcept['products']['variationLabels']['mapping'] ?? [],
|
|
'variationLabels' => $this->getVariationLabels(),
|
|
];
|
|
}
|
|
|
|
public function handleUpdate()
|
|
{
|
|
$data = $this->getData();
|
|
|
|
$productsVariationLabels = [
|
|
'default' => !empty($data['products']['variationLabels']['default']) ? (int) $data['products']['variationLabels']['default'] : null,
|
|
'mapping' => [],
|
|
];
|
|
|
|
foreach ($data['products']['variationLabels']['mapping'] ?? [] as $key => $item) {
|
|
if ($key === 0 || !empty($item['delete'])) {
|
|
continue;
|
|
}
|
|
|
|
if (empty($item['labelId']) || (empty($item['value']) && empty($item['sapFieldWithValue']))) {
|
|
continue;
|
|
}
|
|
|
|
$productsVariationLabels['mapping'][] = [
|
|
'position' => (int) ($item['position'] ?? 0),
|
|
'labelId' => (int) $item['labelId'],
|
|
'value' => $item['value'],
|
|
'sapFieldWithValue' => !empty($item['sapFieldWithValue']) ? $item['sapFieldWithValue'] : null,
|
|
'sapFieldLabelValue' => !empty($item['sapFieldLabelValue']) ? $item['sapFieldLabelValue'] : null,
|
|
];
|
|
}
|
|
|
|
usort($productsVariationLabels['mapping'], fn ($a, $b) => $a['position'] <=> $b['position']);
|
|
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
$oc = $dbcfg->loadValue('outdoorconcept') ?: [];
|
|
$oc['products']['variationLabels'] = $productsVariationLabels;
|
|
$dbcfg->saveValue('outdoorconcept', $oc);
|
|
|
|
$this->configuration->refreshDynamicConfiguration();
|
|
}
|
|
|
|
public function getLabel()
|
|
{
|
|
return 'Outdoor concept';
|
|
}
|
|
|
|
private function getVariationLabels(): array
|
|
{
|
|
return sqlQueryBuilder()
|
|
->select('id, label as name')
|
|
->from('products_variations_choices_labels')
|
|
->execute()
|
|
->fetchAllKeyValue();
|
|
}
|
|
}
|