Skip to content

Commit c64f9d9

Browse files
mstrzyzewskicieslix
authored andcommitted
Add configuration for reservations cron
1 parent 4bb58d8 commit c64f9d9

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

Cron/CleanReservations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class CleanReservations
1515
{
16-
const RESERVATIONS_CONFIG_KEY = 'allegro/order/reservations_enabled';
16+
const RESERVATIONS_CRON_CONFIG_KEY = 'allegro/order/reservations_cron_enabled';
1717

1818
/** @var Logger */
1919
private $logger;
@@ -41,7 +41,7 @@ public function __construct(
4141

4242
public function execute()
4343
{
44-
if ($this->scopeConfig->getValue(self::RESERVATIONS_CONFIG_KEY)) {
44+
if ($this->scopeConfig->getValue(self::RESERVATIONS_CRON_CONFIG_KEY)) {
4545
$this->logger->addInfo("Cronjob clean reservations is executed.");
4646
$this->allegroReservation->cleanOldReservations();
4747
}

Model/Configuration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Configuration
1616
const DESCRIPTION_ATTRIBUTE_CONFIG_PATH = 'allegro/offer_create/description_attribute';
1717
const STORE_ID_CONFIG_PATH = 'allegro/order/store';
1818
const RESERVATIONS_ENABLED_CONFIG_PATH = 'allegro/order/reservations_enabled';
19+
const RESERVATIONS_CRON_ENABLED_CONFIG_PATH = 'allegro/order/reservations_cron_enabled';
1920
const LAST_EVENT_ID_FLAG_NAME = 'allegro_order_last_event_id';
2021
const LAST_USER_ID_FLAG_NAME = 'allegro_credentials_last_user_id';
2122
const INITIALIZATION_TIME_FLAG_NAME = 'allegro_initialization_time';
@@ -87,6 +88,18 @@ public function areReservationsEnabled(
8788
return $this->scopeConfig->isSetFlag(self::RESERVATIONS_ENABLED_CONFIG_PATH, $scopeType, $scopeCode);
8889
}
8990

91+
/**
92+
* @param string $scopeType
93+
* @param string|null $scopeCode
94+
* @return bool
95+
*/
96+
public function isReservationsCronEnabled(
97+
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
98+
?string $scopeCode = null
99+
): bool {
100+
return $this->scopeConfig->isSetFlag(self::RESERVATIONS_CRON_ENABLED_CONFIG_PATH, $scopeType, $scopeCode);
101+
}
102+
90103
/**
91104
* @return string|null
92105
*/

Model/OrderImporter/AllegroReservation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function cleanOldReservations()
173173
{
174174
$tenDaysAgo = (new \DateTime())->modify('-10 day');
175175
$searchCriteria = $this->searchCriteriaBuilder
176-
->addFilter('created_at', $tenDaysAgo->format('Y-m-d 12:00:00'), 'lteq')
176+
->addFilter('created_at', $tenDaysAgo, 'lteq')
177177
->create();
178178

179179
$reservations = $this->reservationRepository->getList($searchCriteria);

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
<label>Reservations enabled</label>
7373
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
7474
</field>
75+
<field id="reservations_cron_enabled" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
76+
<depends>
77+
<field id="reservations_enabled">1</field>
78+
</depends>
79+
<label>Cron for cleaning old reservations enabled</label>
80+
<comment>Cron deletes reservations older than 10 days</comment>
81+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
82+
</field>
7583
<field id="store" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
7684
<label>Store to create new orders</label>
7785
<source_model>Magento\Store\Model\System\Store</source_model>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<stock_synchronization_enabled>1</stock_synchronization_enabled>
1616
<tracking_number_sending_enabled>1</tracking_number_sending_enabled>
1717
<reservations_enabled>1</reservations_enabled>
18+
<reservations_cron_enabled>0</reservations_cron_enabled>
1819
<overpayment_status>Pending:allegro_overpayment</overpayment_status>
1920
<underpayment_status>Pending:allegro_underpayment</underpayment_status>
2021
</order>

etc/db_schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<column xsi:type="int" name="reservation_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Reservation ID"/>
7272
<column xsi:type="varchar" name="checkout_form_id" nullable="false" comment="Checkout form ID"/>
7373
<column xsi:type="varchar" name="sku" nullable="false" comment="Product SKU"/>
74-
<column xsi:type="datetime" name="created_at" nullable="false" comment="Creation date"/>
74+
<column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Creation date"/>
7575
<constraint xsi:type="foreign" referenceId="FOREIGN" table="allegro_reservations" column="reservation_id" referenceTable="inventory_reservation" referenceColumn="reservation_id" onDelete="CASCADE"/>
7676
<constraint xsi:type="primary" referenceId="PRIMARY">
7777
<column name="entity_id"/>

i18n/pl_PL.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,5 @@
172172
"Reservation with ID: %1 has been successfully deleted","Rezerwacja o ID: %1 została pomyślnie usunięta"
173173
"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"
174174
"Creation date","Data utworzenia"
175+
"Cron for cleaning old reservations enabled","Cron do czyszczenia starych rezerwacji jest włączony"
176+
"Cron deletes reservations older than 10 days","Cron usuwa rezerwacje starsze niż 10 dni"

0 commit comments

Comments
 (0)