112 lines
3.3 KiB
PHP
112 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\DropshipBundle\Admin;
|
|
|
|
use KupShop\DropshipBundle\Util\TransferLocator;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use KupShop\KupShopBundle\Util\System\BundleFinder;
|
|
|
|
class Dropshipment extends \Window
|
|
{
|
|
protected $required = [
|
|
'name' => true,
|
|
'source_url' => true,
|
|
];
|
|
|
|
protected $defaults = [
|
|
'active' => 1,
|
|
];
|
|
|
|
protected TransferLocator $transferLocator;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->transferLocator = ServiceContainer::getService(TransferLocator::class);
|
|
}
|
|
|
|
public function processFormData(): array
|
|
{
|
|
$data = parent::processFormData();
|
|
$this->unserializeCustomData($data);
|
|
$r = array_filter($data['data']['restrictions'] ?? [], fn ($v) => !empty($v));
|
|
if (count($r) > 0) {
|
|
if (empty($r['values']) || empty($r['tagName'])) {
|
|
$this->addError(translate('restrictionsValidationError'));
|
|
}
|
|
|
|
if (!empty($r['values'])) {
|
|
$data['data']['restrictions']['values'] = preg_replace('/\s+/', ' ', trim($r['values']));
|
|
}
|
|
}
|
|
|
|
$this->serializeCustomData($data);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function get_vars()
|
|
{
|
|
$vars = parent::get_vars();
|
|
|
|
$vars['body']['configurationTemplate'] = $this->getConfigurationTemplate($vars['body']['data']['type'] ?? null);
|
|
$vars['body']['types'] = [];
|
|
foreach ($this->transferLocator->getTransfers() as $type => $transfer) {
|
|
$vars['body']['types'][$type] = $transfer::getName();
|
|
}
|
|
if ($this->getAction() == 'edit') {
|
|
$vars['body']['configurationData'] = $this->transferLocator->getTransfer($vars['body']['data']['type'])->getConfigurationVariables();
|
|
}
|
|
if (findModule(\Modules::INVOICES)) {
|
|
$vars['body']['invoices'] = sqlQueryBuilder()
|
|
->select('id, name')
|
|
->from('invoice_numbers')
|
|
->execute()
|
|
->fetchAllKeyValue();
|
|
|
|
$vars['body']['invoices'] = ['' => 'Žádná fakturační řada'] + $vars['body']['invoices'];
|
|
}
|
|
|
|
$vars['body']['data']['configuration'] = json_decode($vars['body']['data']['configuration'] ?? '', true) ?: [];
|
|
|
|
$this->unserializeCustomData($vars['body']['data']);
|
|
|
|
return $vars;
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
$data = parent::getData();
|
|
|
|
if (getVal('Submit')) {
|
|
$data['active'] = $data['active'] === 'Y' ? 1 : 0;
|
|
|
|
if (!empty($data['configuration'])) {
|
|
$data['configuration'] = $this->transferLocator->getTransfer($data['type'])
|
|
->prepareConfigurationData($data['configuration']);
|
|
}
|
|
|
|
$data['configuration'] = json_encode($data['configuration'] ?? []);
|
|
|
|
$this->serializeCustomData($data);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function getConfigurationTemplate(?string $type): ?string
|
|
{
|
|
$bundleFinder = ServiceContainer::getService(BundleFinder::class);
|
|
|
|
$template = 'dropshipment.configuration.'.$type.'.tpl';
|
|
if (file_exists($bundleFinder->getBundlesPath('Admin/templates/window/')['DropshipBundle'].$template)) {
|
|
return $template;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return Dropshipment::class;
|