Skip to content

Commit

Permalink
Merge branch 'master' of github.com:macopedia/magento2-allegro
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslix committed Oct 29, 2020
2 parents 5ebcf25 + c64f9d9 commit 8018b2b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cron/CleanReservations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
13 changes: 13 additions & 0 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Model/OrderImporter/AllegroReservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
<label>Reservations enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="reservations_cron_enabled" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<depends>
<field id="reservations_enabled">1</field>
</depends>
<label>Cron for cleaning old reservations enabled</label>
<comment>Cron deletes reservations older than 10 days</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="store" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Store to create new orders</label>
<source_model>Magento\Store\Model\System\Store</source_model>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<stock_synchronization_enabled>1</stock_synchronization_enabled>
<tracking_number_sending_enabled>1</tracking_number_sending_enabled>
<reservations_enabled>1</reservations_enabled>
<reservations_cron_enabled>0</reservations_cron_enabled>
<overpayment_status>Pending:allegro_overpayment</overpayment_status>
<underpayment_status>Pending:allegro_underpayment</underpayment_status>
</order>
Expand Down
2 changes: 1 addition & 1 deletion etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<column xsi:type="int" name="reservation_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Reservation ID"/>
<column xsi:type="varchar" name="checkout_form_id" nullable="false" comment="Checkout form ID"/>
<column xsi:type="varchar" name="sku" nullable="false" comment="Product SKU"/>
<column xsi:type="datetime" name="created_at" nullable="false" comment="Creation date"/>
<column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Creation date"/>
<constraint xsi:type="foreign" referenceId="FOREIGN" table="allegro_reservations" column="reservation_id" referenceTable="inventory_reservation" referenceColumn="reservation_id" onDelete="CASCADE"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="entity_id"/>
Expand Down
2 changes: 2 additions & 0 deletions i18n/pl_PL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8018b2b

Please sign in to comment.