first commit
This commit is contained in:
54
class/smarty_plugins/function.pohoda_get_vat_level.php
Normal file
54
class/smarty_plugins/function.pohoda_get_vat_level.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use KupShop\OrderingBundle\Util\Order\OrderItemInfo;
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param Smarty $smarty
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_pohoda_get_vat_level($params, &$smarty)
|
||||
{
|
||||
// TODO: předělat na VatContext + ContextManager @h.prokop
|
||||
static $vats = null;
|
||||
|
||||
if (is_null($vats)) {
|
||||
$vats = [];
|
||||
$vatsSQL = sqlQueryBuilder()->select('*')->from('vats');
|
||||
foreach ($vatsSQL->execute() as $vat) {
|
||||
$data = json_decode($vat['data'], true);
|
||||
$vats[$vat['id_country'] ?? 'CZ'][$vat['vat']] = $data['level'] ?? 'high';
|
||||
}
|
||||
}
|
||||
|
||||
/** @var \Order $order */
|
||||
$order = $params['order'];
|
||||
$item = $params['item'];
|
||||
$country = strtoupper($order['delivery_country'] ?? 'CZ');
|
||||
|
||||
$oss = $order->getFlags()['OSS'] ?? false;
|
||||
|
||||
$POHODA_OSS_VAT_LEVELS = [
|
||||
OrderItemInfo::VAT_HIGH => 'historyHigh',
|
||||
OrderItemInfo::VAT_LOW => 'historyLow',
|
||||
OrderItemInfo::VAT_LOW2 => 'historyThird',
|
||||
OrderItemInfo::VAT_NONE => 'none',
|
||||
];
|
||||
|
||||
$POHODA_VAT_LEVELS = [
|
||||
OrderItemInfo::VAT_HIGH => 'high',
|
||||
OrderItemInfo::VAT_LOW => 'low',
|
||||
OrderItemInfo::VAT_LOW2 => 'third',
|
||||
OrderItemInfo::VAT_NONE => 'none',
|
||||
];
|
||||
|
||||
if ($item['vat'] == 0) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
$level = $vats[$country][$item['vat']] ?? 'high';
|
||||
$levels = $oss ? $POHODA_OSS_VAT_LEVELS : $POHODA_VAT_LEVELS;
|
||||
|
||||
return $levels[$level];
|
||||
}
|
||||
Reference in New Issue
Block a user