Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSP-90 Add a mechanism to avoid growing tables v4 #58

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Model/Config/NostoConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class NostoConfigService

public const ENABLE_PRODUCT_LABELLING_SYNC = 'enableLabelling';

public const ENABLE_STORE_DATA_ABUNDANT_CARTS = 'storeDataAbundantCarts';
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved

public const DAILY_PRODUCT_SYNC_ENABLED = 'dailySynchronization';

public const DAILY_PRODUCT_SYNC_TIME = 'dailySynchronizationTime';
Expand Down
15 changes: 14 additions & 1 deletion src/Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ public function isEnabledProductLabellingSync(?string $channelId = null, ?string
);
}

public function isEnabledStoreDataAbundantCarts($channelId = null, $languageId = null): bool
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->configService->getBool(
NostoConfigService::ENABLE_STORE_DATA_ABUNDANT_CARTS,
$channelId,
$languageId,
);
}

public function isDailyProductSyncEnabled(?string $channelId = null, ?string $languageId = null): bool
{
return $this->configService->getBool(NostoConfigService::DAILY_PRODUCT_SYNC_ENABLED, $channelId, $languageId);
Expand Down Expand Up @@ -258,7 +267,11 @@ public function isOldNostoDataCleanupEnabled($channelId = null, $languageId = nu

public function getOldNostoDataCleanupPeriod($channelId = null, $languageId = null): ?int
{
return $this->configService->getInt(NostoConfigService::OLD_NOSTO_DATA_CLEANUP_PERIOD, $channelId, $languageId);
return $this->configService->getInt(
NostoConfigService::OLD_NOSTO_DATA_CLEANUP_PERIOD,
$channelId,
$languageId,
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ Component.register('nosto-integration-features-flags', {
return options;
},
createOldNostoDataCleanupPeriodOptions() {
const monthPeriods = [3];
const dayPeriods = [7, 30, 60, 90];
const options = [];
const translationAfter = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.after');
const translationMonths = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.months');
const translationDays = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.days');

monthPeriods.forEach((period) => {
dayPeriods.forEach((period) => {
options.push(
{
label: `${translationAfter} ${period} ${translationMonths}`,
label: `${translationAfter} ${period} ${translationDays}`,
value: period,
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@
</sw-inherit-wrapper>
{% endblock %}

{% block nosto_integration_feature_store_data_abundant_carts %}
<sw-inherit-wrapper
:value="currentConfig['storeDataAbundantCarts']"
:inheritedValue="configKey === null ? null : configs['null']['storeDataAbundantCarts']"
@update:value="onUpdateValue('storeDataAbundantCarts', $event)"
>
<template #content="props">
<sw-switch-field
name="storeDataAbundantCarts"
:map-inheritance="props"
:label="$tc('nosto.configuration.featuresFlags.storeDataAbundantCarts')"
:help-text="$tc('nosto.configuration.featuresFlags.storeDataAbundantCartsHelpText')"
:disabled="props.isInherited"
:value="props.currentValue"
@update:value="onUpdateValue('storeDataAbundantCarts', $event)"
/>
</template>
</sw-inherit-wrapper>
{% endblock %}

{% block nosto_integration_daily_synchronization_flag %}
<sw-inherit-wrapper
v-if="configKey === null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
"enableProductPublishedDateTagging": "Kennzeichnung des Veröffentlichungsdatums von Produkten",
"enableReloadRecommendations": "Empfehlungen neu laden, nachdem ein empfohlenes Produkt hinzugefügt wurde",
"enableLabelling": "Synchronisierung der Produktkennzeichnung aktivieren",
"storeDataAbundantCarts": "Speichere Daten für verlassene Warenkörbe",
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
"enableDailySynchronization": "Tägliche Produktsynchronisierung aktivieren",
"enableDailySynchronizationHelp": "Wenn das Feld aktiviert ist, werden die Produkte jeden Tag zur angegebenen Zeit synchronisiert",
"timeDailySynchronization": "Zeit für die tägliche Produktsynchronisierung",
"timeDailySynchronizationHelp": "Die Option gibt an, zu welcher Uhrzeit die t\u00e4gliche Produktsynchronisierung synchronisiert werden soll",
"enableProductPublishedDateTaggingHelpText": "Wenn das Kontrollkästchen aktiviert ist, wird auch das Veröffentlichungsdatum des Produkts markiert.",
"enableReloadRecommendationsHelpText": "Wenn das Kontrollkästchen aktiviert ist, werden die Empfehlungen nach dem Hinzufügen eines empfohlenen Produkts neu geladen",
"enableLabellingHelpText": "Wenn das Kontrollkästchen aktiviert ist, werden die Produktetiketten an Nosto gesendet.",
"storeDataAbundantCartsHelpText": "Diese Konfigurationsoption steuert, ob Daten für abgebrochene Warenkörbe in der entsprechenden Tabelle gespeichert werden sollen. Wenn diese Option aktiviert ist, wird das System neue Zeilen in der Tabelle für jeden abgebrochenen Warenkorb abrufen und erstellen. Wenn sie deaktiviert ist, werden keine neuen Zeilen hinzugefügt, was potenziell Leistungsprobleme verhindern kann.",
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
"categoryNamingHelpText": "Produktkategorienamen enthalten die Kategorie-ID oder nicht",
"categoryNaming": "Produktkategorienamen",
"categoryBlocklist": "Kategorie Ausschluss",
Expand All @@ -124,7 +126,7 @@
},
"oldNostoDataPeriod": {
"after": "Nach",
"months": "monate"
"days": "Tagen"
}
},
"search-navigation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
"enableProductPublishedDateTagging": "Enable Product Published Date Tagging",
"enableReloadRecommendations": "Reload Recommendations After Adding a recommended product",
"enableLabelling": "Enable Product Labelling Sync",
"storeDataAbundantCarts": "Store data for abundant carts",
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
"enableDailySynchronization": "Enable Daily Product Synchronization",
"enableDailySynchronizationHelp": "If the field is enabled products will be synchronized at the mentioned time each day",
"timeDailySynchronization": "Time for Daily Product Synchronization",
"timeDailySynchronizationHelp": "The option specifies at which time to sync daily product synchronization",
"enableProductPublishedDateTaggingHelpText": "If the checkbox is checked, product publishing date will be tagged as well.",
"enableReloadRecommendationsHelpText": "If the checkbox is checked, the recommendations will be reloaded after adding a recommended product",
"enableLabellingHelpText": "If the checkbox is checked, product labels will be sent to Nosto",
"storeDataAbundantCartsHelpText": "This configuration option controls whether data for abandoned carts should be stored in the relevant table. When this option is enabled, the system will fetch and create new rows in the table for each abandoned cart. If disabled, no new rows will be added, potentially preventing performance issues.",
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
"categoryNamingHelpText": "Product category names will contain the category ID or not",
"categoryNaming": "Product Category Names",
"categoryBlocklist": "Category Exclusion",
Expand All @@ -124,7 +126,7 @@
},
"oldNostoDataPeriod": {
"after": "After",
"months": "months"
"days": "days"
}
},
"search-navigation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public function run(): void
{
try {
$isNostoDataCleanupEnabled = $this->configProvider->isOldNostoDataCleanupEnabled();
$monthPeriod = $this->configProvider->getOldNostoDataCleanupPeriod();
$dayPeriod = $this->configProvider->getOldNostoDataCleanupPeriod();

if ($isNostoDataCleanupEnabled && $monthPeriod) {
$numberOfMonthsBeforeToday = new DateTime(' - ' . $monthPeriod . ' month');
if ($isNostoDataCleanupEnabled && $dayPeriod) {
$numberOfDaysBeforeToday = new DateTime(' - ' . $dayPeriod . ' day');

$this->connection->executeStatement(
'DELETE FROM nosto_integration_checkout_mapping WHERE created_at <= :timestamp',
[
'timestamp' => $numberOfMonthsBeforeToday->format(Defaults::STORAGE_DATE_FORMAT),
'timestamp' => $numberOfDaysBeforeToday->format(Defaults::STORAGE_DATE_FORMAT),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nosto\NostoIntegration\Entity\CheckoutMapping\CheckoutMappingDefinition;
use Nosto\NostoIntegration\Entity\CheckoutMapping\CheckoutMappingEntity;
use Nosto\NostoIntegration\Model\ConfigProvider;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
Expand All @@ -22,16 +23,21 @@ class RestoreUrlService
public function __construct(
private readonly EntityRepository $mappingRepository,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly ConfigProvider $configProvider,
private readonly RequestStack $requestStack,
) {
}

public function getCurrentRestoreUrl(SalesChannelContext $context): string
public function getCurrentRestoreUrl(SalesChannelContext $context): ?string
{
$current = $this->fetchFromDb($context->getToken(), $context->getContext());
return $this->generate(
$current ? $current->getId() : $this->createNew($context->getToken(), $context->getContext()),
);
if ($this->configProvider->isEnabledStoreDataAbundantCarts()) {
$current = $this->fetchFromDb($context->getToken(), $context->getContext());
return $this->generate(
$current ? $current->getId() : $this->createNew($context->getToken(), $context->getContext()),
);
}

return null;
Radomir98 marked this conversation as resolved.
Show resolved Hide resolved
}

protected function fetchFromDb(string $token, Context $context): ?CheckoutMappingEntity
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/CustomerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getNostoCustomer(CustomerEntity $customer, Context $context): Cu
return $this->builder->build($customer, $context);
}

public function getRestoreCartLink(SalesChannelContext $context): string
public function getRestoreCartLink(SalesChannelContext $context): ?string
{
return $this->restoreUrlService->getCurrentRestoreUrl($context);
}
Expand Down
Loading