109 lines
2.5 KiB
PHP
109 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\BalikonosBundle\Admin\Tabs;
|
|
|
|
use KupShop\AdminBundle\Admin\WindowTab;
|
|
use Query\Operator;
|
|
|
|
class BalikobotDeliveryTab extends WindowTab
|
|
{
|
|
protected $title = 'flapBalikobotDelivery';
|
|
|
|
protected $template = '';
|
|
|
|
public static function getTypes()
|
|
{
|
|
return [
|
|
'deliveryDelivery' => 1,
|
|
];
|
|
}
|
|
|
|
public static function isAllowed()
|
|
{
|
|
return findModule(\Modules::BALIKONOS, 'provider') === 'balikobot';
|
|
}
|
|
|
|
public function getVars($smarty_tpl_vars)
|
|
{
|
|
$id = $this->getId();
|
|
if (empty($id)) {
|
|
return [];
|
|
}
|
|
|
|
$deliveryRow = $this->getDeliveryRow($id);
|
|
if (empty($deliveryRow['class'])) {
|
|
return [];
|
|
}
|
|
|
|
$this->setTemplate($deliveryRow['class']);
|
|
|
|
$deliveryRow['custom_data'] = json_decode($deliveryRow['data'] ?? '', true);
|
|
|
|
return [
|
|
'balikobot' => $deliveryRow['custom_data']['balikobot'] ?? [],
|
|
];
|
|
}
|
|
|
|
public function isVisible()
|
|
{
|
|
$id = getVal('ID');
|
|
if (empty($id)) {
|
|
return false;
|
|
}
|
|
|
|
$deliveryRow = $this->getDeliveryRow($id);
|
|
if (empty($deliveryRow['class'])) {
|
|
return false;
|
|
}
|
|
|
|
$this->setTemplate($deliveryRow['class']);
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function getDeliveryRow($id): array|false
|
|
{
|
|
return sqlQueryBuilder()
|
|
->select('*')
|
|
->from('delivery_type_delivery')
|
|
->where(Operator::equals(['id' => $id]))
|
|
->setMaxResults(1)
|
|
->execute()
|
|
->fetchAssociative();
|
|
}
|
|
|
|
public function handleUpdate()
|
|
{
|
|
$data = $this->getData();
|
|
if (!isset($data)) {
|
|
return;
|
|
}
|
|
|
|
$customData = $this->window->getCustomData();
|
|
if ($data['balikobot']) {
|
|
$customData['balikobot'] = array_filter($data['balikobot'], function ($v) {
|
|
return !($v === '');
|
|
});
|
|
}
|
|
$this->window->setCustomData($customData);
|
|
}
|
|
|
|
protected function setTemplate($class)
|
|
{
|
|
$template = 'balikobot/delivery.'.$class.'.tpl';
|
|
$this->template = $this->templateExists($template) ? $template : 'balikobot/delivery.common.tpl';
|
|
}
|
|
|
|
public function getLabel()
|
|
{
|
|
return translate('balikobot', 'suppliers');
|
|
}
|
|
|
|
protected function templateExists(string $template): bool
|
|
{
|
|
$smarty = createSmarty(true, true);
|
|
|
|
return $smarty->templateExists($template);
|
|
}
|
|
}
|