85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\PompoBundle\DRS\EventSubscriber;
|
|
|
|
use External\PompoBundle\DRS\Synchronizer\POSOrderSynchronizer;
|
|
use External\PompoBundle\DRS\Synchronizer\PriceSynchronizer;
|
|
use External\PompoBundle\DRS\Synchronizer\StockSynchronizer;
|
|
use External\PompoBundle\DRS\Synchronizer\UserCouponSynchronizer;
|
|
use External\PompoBundle\Util\Configuration;
|
|
use External\PompoBundle\Util\PompoUtil;
|
|
use KupShop\AdminBundle\Util\ActivityLog;
|
|
use KupShop\KupShopBundle\Event\CronEvent;
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
class CronSubscriber implements EventSubscriberInterface
|
|
{
|
|
public function __construct(
|
|
private PompoUtil $pompoUtil,
|
|
private Configuration $configuration,
|
|
private PriceSynchronizer $priceSynchronizer,
|
|
private StockSynchronizer $stockSynchronizer,
|
|
) {
|
|
}
|
|
|
|
public static function getSubscribedEvents()
|
|
{
|
|
return [
|
|
CronEvent::RUN_FREQUENT => [
|
|
['synchronizeFrequent', 200],
|
|
],
|
|
CronEvent::RUN_EXPENSIVE => [
|
|
['synchronizeExpensive', 200],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function synchronizeFrequent(): void
|
|
{
|
|
if (!$this->configuration->isPompo()) {
|
|
return;
|
|
}
|
|
|
|
// Stahne objednavky z pokladen do e-shopu a odesle vygenerovane kupony do DRSu
|
|
$this->pompoUtil->synchronizeDRS(
|
|
[
|
|
POSOrderSynchronizer::getType(),
|
|
UserCouponSynchronizer::getType(),
|
|
]
|
|
);
|
|
}
|
|
|
|
public function synchronizeExpensive(): void
|
|
{
|
|
// plna synchronizace skladu
|
|
$this->runDRSStockFullSync();
|
|
|
|
// Sesynchronizuje akcni ceny, u kterych bude zacinat nebo koncit platnost.
|
|
$this->priceSynchronizer->processActionPrices();
|
|
}
|
|
|
|
private function runDRSStockFullSync(): void
|
|
{
|
|
if (!$this->configuration->isPompo()) {
|
|
return;
|
|
}
|
|
|
|
$dayOfWeek = date('w');
|
|
$hour = date('G');
|
|
|
|
// TED PRES SEZONU SPOUSTIME KAZDOU NOC. RESIME PROBLEM, KDY DRS NEVYGENERUJE ZMENU SKLADU NAPR. PRI PRIJMU ZBOZI
|
|
// TAK ABY SE TY CHYBY CO NEJRYCHLEJI OPRAVILI
|
|
|
|
// pokud je nedele nocni hodina (22-23:59) a nebo pondeli brzo rano (00-03), tak spustim resync DRS skladu
|
|
// if (($dayOfWeek == 0 || $dayOfWeek == 1) && ($hour >= 22 || $hour <= 3))
|
|
|
|
addActivityLog(ActivityLog::SEVERITY_NOTICE, ActivityLog::TYPE_SYNC, '[DRS] Plná synchronizace skladu: spouštím');
|
|
$processedItems = $this->stockSynchronizer->syncFullStock();
|
|
addActivityLog(ActivityLog::SEVERITY_NOTICE, ActivityLog::TYPE_SYNC, '[DRS] Plná synchronizace skladu: dokončeno', [
|
|
'processedItemsCount' => $processedItems,
|
|
]);
|
|
}
|
|
}
|