From c64f9d9b210f686cb2020ada1126d4d8affd0cea Mon Sep 17 00:00:00 2001 From: Maksymilian Strzyzewski Date: Thu, 29 Oct 2020 07:40:35 +0100 Subject: [PATCH] Add configuration for reservations cron --- Cron/CleanReservations.php | 4 ++-- Model/Configuration.php | 13 +++++++++++++ Model/OrderImporter/AllegroReservation.php | 2 +- etc/adminhtml/system.xml | 8 ++++++++ etc/config.xml | 1 + etc/db_schema.xml | 2 +- i18n/pl_PL.csv | 2 ++ 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Cron/CleanReservations.php b/Cron/CleanReservations.php index 5534ef6..8ae308e 100644 --- a/Cron/CleanReservations.php +++ b/Cron/CleanReservations.php @@ -13,7 +13,7 @@ */ class CleanReservations { - const RESERVATIONS_CONFIG_KEY = 'allegro/order/reservations_enabled'; + const RESERVATIONS_CRON_CONFIG_KEY = 'allegro/order/reservations_cron_enabled'; /** @var Logger */ private $logger; @@ -41,7 +41,7 @@ public function __construct( public function execute() { - if ($this->scopeConfig->getValue(self::RESERVATIONS_CONFIG_KEY)) { + if ($this->scopeConfig->getValue(self::RESERVATIONS_CRON_CONFIG_KEY)) { $this->logger->addInfo("Cronjob clean reservations is executed."); $this->allegroReservation->cleanOldReservations(); } diff --git a/Model/Configuration.php b/Model/Configuration.php index e748370..27a0168 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -16,6 +16,7 @@ class Configuration const DESCRIPTION_ATTRIBUTE_CONFIG_PATH = 'allegro/offer_create/description_attribute'; const STORE_ID_CONFIG_PATH = 'allegro/order/store'; const RESERVATIONS_ENABLED_CONFIG_PATH = 'allegro/order/reservations_enabled'; + const RESERVATIONS_CRON_ENABLED_CONFIG_PATH = 'allegro/order/reservations_cron_enabled'; const LAST_EVENT_ID_FLAG_NAME = 'allegro_order_last_event_id'; const LAST_USER_ID_FLAG_NAME = 'allegro_credentials_last_user_id'; const INITIALIZATION_TIME_FLAG_NAME = 'allegro_initialization_time'; @@ -87,6 +88,18 @@ public function areReservationsEnabled( return $this->scopeConfig->isSetFlag(self::RESERVATIONS_ENABLED_CONFIG_PATH, $scopeType, $scopeCode); } + /** + * @param string $scopeType + * @param string|null $scopeCode + * @return bool + */ + public function isReservationsCronEnabled( + string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + ?string $scopeCode = null + ): bool { + return $this->scopeConfig->isSetFlag(self::RESERVATIONS_CRON_ENABLED_CONFIG_PATH, $scopeType, $scopeCode); + } + /** * @return string|null */ diff --git a/Model/OrderImporter/AllegroReservation.php b/Model/OrderImporter/AllegroReservation.php index ad5863e..279b0bb 100644 --- a/Model/OrderImporter/AllegroReservation.php +++ b/Model/OrderImporter/AllegroReservation.php @@ -173,7 +173,7 @@ public function cleanOldReservations() { $tenDaysAgo = (new \DateTime())->modify('-10 day'); $searchCriteria = $this->searchCriteriaBuilder - ->addFilter('created_at', $tenDaysAgo->format('Y-m-d 12:00:00'), 'lteq') + ->addFilter('created_at', $tenDaysAgo, 'lteq') ->create(); $reservations = $this->reservationRepository->getList($searchCriteria); diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a125089..7d22395 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -72,6 +72,14 @@ Magento\Config\Model\Config\Source\Yesno + + + 1 + + + Cron deletes reservations older than 10 days + Magento\Config\Model\Config\Source\Yesno + Magento\Store\Model\System\Store diff --git a/etc/config.xml b/etc/config.xml index 4581c05..12577af 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -15,6 +15,7 @@ 1 1 1 + 0 Pending:allegro_overpayment Pending:allegro_underpayment diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 2b9b104..447a423 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -71,7 +71,7 @@ - + diff --git a/i18n/pl_PL.csv b/i18n/pl_PL.csv index cfe7063..da274b7 100644 --- a/i18n/pl_PL.csv +++ b/i18n/pl_PL.csv @@ -172,3 +172,5 @@ "Reservation with ID: %1 has been successfully deleted","Rezerwacja o ID: %1 została pomyślnie usunięta" "Something went wrong while trying to delete reservation with ID: %1","Coś poszło nie tak podczas próby usunięcia rezerwacji o ID: %1" "Creation date","Data utworzenia" +"Cron for cleaning old reservations enabled","Cron do czyszczenia starych rezerwacji jest włączony" +"Cron deletes reservations older than 10 days","Cron usuwa rezerwacje starsze niż 10 dni"