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 e6a48f4..7c96cb4 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -17,6 +17,7 @@ class Configuration const PRICE_ATTRIBUTE_CONFIG_PATH = 'allegro/offer_create/price_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 PRICE_POLICY_ENABLED_CONFIG_PATH = 'allegro/price_policy/price_policy_enabled'; const PERCENT_INCREASE_CONFIG_PATH = 'allegro/price_policy/percent_increase'; const LAST_EVENT_ID_FLAG_NAME = 'allegro_order_last_event_id'; @@ -90,6 +91,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); + } + /** * @param string $scopeType * @param string|null $scopeCode 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 d1da3ae..0cc6b0a 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 a9b4fca..4eb4f2b 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 ebbc50a..80f87e5 100644 --- a/i18n/pl_PL.csv +++ b/i18n/pl_PL.csv @@ -177,3 +177,5 @@ "Product attribute for getting price","Atrybut produktu do pobrania ceny" "Attributes are taken from the default scope","Atrybuty są pobierane z domyślnego widoku sklepu" "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"