Skip to content

Commit

Permalink
Merge pull request #32 from sequra/fix/CS-5957
Browse files Browse the repository at this point in the history
Fix the issue with sending statistical data
  • Loading branch information
m1k3lm authored Oct 16, 2024
2 parents 1fb892f + d521cf2 commit 3f371a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
38 changes: 22 additions & 16 deletions Services/BusinessLogic/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use SeQura\Core\BusinessLogic\Domain\Order\Service\OrderService as SeQuraOrderService;
use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilderFactory;
use Sequra\Core\Services\BusinessLogic\Utility\SeQuraTranslationProvider;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory;

/**
* Class OrderService
Expand All @@ -47,6 +48,10 @@ class OrderService implements ShopOrderService
* @var SearchCriteriaBuilder
*/
private $searchOrderCriteriaBuilder;
/**
* @var OrderCollectionFactory
*/
private $collectionFactory;
/**
* @var OrderRepositoryInterface
*/
Expand Down Expand Up @@ -77,17 +82,19 @@ class OrderService implements ShopOrderService
private $createOrderRequestBuilderFactory;

public function __construct(
SearchCriteriaBuilder $searchOrderCriteriaBuilder,
OrderRepositoryInterface $shopOrderRepository,
OrderManagementInterface $orderManagement,
CartManagementInterface $cartManagement,
SeQuraOrderRepositoryInterface $seQuraOrderRepository,
SeQuraTranslationProvider $translationProvider,
CartRepositoryInterface $cartProvider,
SearchCriteriaBuilder $searchOrderCriteriaBuilder,
OrderCollectionFactory $collectionFactory,
OrderRepositoryInterface $shopOrderRepository,
OrderManagementInterface $orderManagement,
CartManagementInterface $cartManagement,
SeQuraOrderRepositoryInterface $seQuraOrderRepository,
SeQuraTranslationProvider $translationProvider,
CartRepositoryInterface $cartProvider,
CreateOrderRequestBuilderFactory $createOrderRequestBuilderFactory
)
{
$this->searchOrderCriteriaBuilder = $searchOrderCriteriaBuilder;
$this->collectionFactory = $collectionFactory;
$this->shopOrderRepository = $shopOrderRepository;
$this->orderManagement = $orderManagement;
$this->cartManagement = $cartManagement;
Expand All @@ -114,19 +121,18 @@ public function getStatisticsOrderIds(int $page, int $limit = 5000): array
$fromDate = clone $toDate;
$fromDate->modify('-7 days');

$searchCriteria = $this->searchOrderCriteriaBuilder
->addFilter('created_at', $fromDate->format('Y-m-d H:i:s'), 'gteq')
->addFilter('created_at', $toDate->format('Y-m-d H:i:s'), 'lteq')
->setCurrentPage($page + 1)
->setPageSize($limit)
->create();
$collection = $this->collectionFactory
->create()
->setPage($page, $limit)
->addFieldToFilter('created_at', ['gteq' => $fromDate->format('Y-m-d H:i:s')])
->addFieldToFilter('created_at', ['lteq' => $toDate->format('Y-m-d H:i:s')]);

$orderList = $this->shopOrderRepository->getList($searchCriteria);
if ($page * $limit > $orderList->getTotalCount()) {
$count = $collection->getSize();
if ($page !== 1 && $page > round($count / $limit)) {
return [];
}

return array_column($orderList->getData(), 'entity_id');
return array_column($collection->getData(), 'entity_id');
}

/**
Expand Down
33 changes: 17 additions & 16 deletions Services/BusinessLogic/StatisticalDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace Sequra\Core\Services\BusinessLogic;

use SeQura\Core\BusinessLogic\Domain\SendReport\Models\SendReport;
use SeQura\Core\BusinessLogic\Domain\StatisticalData\Models\StatisticalData;
use SeQura\Core\BusinessLogic\Domain\StatisticalData\Services\StatisticalDataService as CoreStatisticalDataService;
use SeQura\Core\BusinessLogic\Domain\Stores\Services\StoreService;
use SeQura\Core\Infrastructure\ServiceRegister;
use SeQura\Core\Infrastructure\Utility\TimeProvider;

/**
* Class StatisticalDataService
Expand All @@ -16,33 +14,36 @@
class StatisticalDataService extends CoreStatisticalDataService
{
private const SCHEDULE_TIME = '4 am';
private const SCHEDULE_TIME_NEXT_DAY = '4 am +1 day';

/**
* @inheirtDoc
*/
public function saveStatisticalData(StatisticalData $statisticalData): void
{
$this->statisticalDataRepository->setStatisticalData($statisticalData);
}

/**
* @inheirtDoc
*/
public function getContextsForSendingReport(): array
{
if ($this->timeProvider->getCurrentLocalTime()->getTimestamp()
!== strtotime(self::SCHEDULE_TIME)) {
return [];
if (!$statisticalData->isSendStatisticalData()) {
return;
}

if ($this->timeProvider->getCurrentLocalTime()->getTimestamp() <= strtotime(self::SCHEDULE_TIME)) {
$sendReport = new SendReport(strtotime(self::SCHEDULE_TIME));
} else {
$sendReport = new SendReport(strtotime(self::SCHEDULE_TIME_NEXT_DAY));
}

return $this->getStoreService()->getConnectedStores();
$this->sendReportRepository->setSendReport(
$sendReport
);
}

/**
* @return StoreService
* @inheirtDoc
*/
private function getStoreService(): StoreService
public function setSendReportTime(): void
{
return ServiceRegister::getService(StoreService::class);
$time = strtotime(self::SCHEDULE_TIME_NEXT_DAY);
$this->sendReportRepository->setSendReport(new SendReport($time));
}
}

0 comments on commit 3f371a0

Please sign in to comment.