103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\PohodaBundle\Utils;
|
|
|
|
use KupShop\KupShopBundle\Util\Logging\SentryLogger;
|
|
use KupShop\PohodaBundle\Utils\Tools\TransformHelper;
|
|
use KupShop\PohodaBundle\Utils\Tools\VatHelper;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
trait PohodaBase
|
|
{
|
|
#[Required]
|
|
public SentryLogger $sentryLogger;
|
|
|
|
#[Required]
|
|
public LoggerInterface $logger;
|
|
|
|
#[Required]
|
|
public PohodaConnector $pohodaConnector;
|
|
|
|
#[Required]
|
|
public TransformHelper $transformHelper;
|
|
|
|
#[Required]
|
|
public VatHelper $vatHelper;
|
|
|
|
protected $fullSync = false;
|
|
|
|
/**
|
|
* @return string|string[]
|
|
*/
|
|
public function replace($xml)
|
|
{
|
|
$replaces = [
|
|
'{KUPSHOP_ICO}' => $this->getICO(),
|
|
];
|
|
|
|
return str_replace(array_keys($replaces), array_values($replaces), $xml);
|
|
}
|
|
|
|
/**
|
|
* @return null
|
|
*/
|
|
public function getICO()
|
|
{
|
|
$config = $this->pohodaConnector->getCurrent();
|
|
|
|
return !empty($config['ico']) ? $config['ico'] : \Settings::getDefault()->shop_ico;
|
|
}
|
|
|
|
public function isFullSync(): bool
|
|
{
|
|
return $this->fullSync;
|
|
}
|
|
|
|
public function setFullSync(bool $fullSync): void
|
|
{
|
|
$this->fullSync = $fullSync;
|
|
}
|
|
|
|
protected function addActivityLog($severity, $msg, $data)
|
|
{
|
|
return $this->pohodaConnector->addActivityLog($severity, $msg, $data);
|
|
}
|
|
|
|
public function addRequestLog($message, $data)
|
|
{
|
|
$this->logger->notice('['.$this->pohodaConnector->getmServerName().']['.$this->addLogSource().'] POHODA REQUEST: '.$message, ['data' => $data]);
|
|
}
|
|
|
|
public function addResponseLog($message, $data)
|
|
{
|
|
$this->logger->notice('['.$this->pohodaConnector->getmServerName().']['.$this->addLogSource().'] POHODA RESPONSE: '.$message, ['data' => $data]);
|
|
}
|
|
|
|
protected function addLogSource()
|
|
{
|
|
if (php_sapi_name() == 'cli') {
|
|
return 'cli';
|
|
} else {
|
|
return 'oth';
|
|
}
|
|
}
|
|
|
|
protected function splitOrdersBymServers($orders)
|
|
{
|
|
$ordersBymServers = [];
|
|
|
|
foreach ($orders as $order_id => $pohoda_id) {
|
|
// fallback kdyz to je ze stare konstrukce
|
|
if (strpos($pohoda_id, '_') === false) {
|
|
$ordersBymServers[0][$order_id] = $pohoda_id;
|
|
continue;
|
|
}
|
|
|
|
$ordersBymServers[strtok($pohoda_id, '_')][$order_id] = substr($pohoda_id, strpos($pohoda_id, '_') + 1);
|
|
}
|
|
|
|
return $ordersBymServers;
|
|
}
|
|
}
|