Skip to content

Commit 187b967

Browse files
authored
notification bar validity now includes time for more narrow settings (#3805)
2 parents 820d223 + 1e4126e commit 187b967

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

src/Component/DateTimeHelper/DateTimeHelper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,17 @@ public function getCurrentDayOfWeek(int $domainId): int
7272
$this->displayTimeZoneProvider->getDisplayTimeZoneByDomainId($domainId),
7373
))->format('N');
7474
}
75+
76+
/**
77+
* @param string $dateTimeString
78+
* @param \DateTimeZone $dateTimeZone
79+
* @return \DateTime
80+
*/
81+
public function createUtcDateTimeByTimeZoneAndString(string $dateTimeString, DateTimeZone $dateTimeZone): DateTime
82+
{
83+
$dateTime = new DateTime($dateTimeString, $dateTimeZone);
84+
$dateTime->setTimezone(new DateTimeZone('UTC'));
85+
86+
return $dateTime;
87+
}
7588
}

src/Component/Redis/CleanStorefrontCacheFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CleanStorefrontCacheFacade
1414
public const string ARTICLES_QUERY_KEY_PART = 'ArticlesQuery';
1515
public const string SETTINGS_QUERY_KEY_PART = 'SettingsQuery';
1616
public const string SLIDER_ITEMS_QUERY_KEY_PART = 'SliderItemsQuery';
17+
public const string NOTIFICATION_BARS_QUERY_KEY_PART = 'NotificationBars';
1718

1819
/**
1920
* @param \Redis $storefrontGraphqlQueryClient

src/Form/Admin/NotificationBar/NotificationBarFormType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Shopsys\FormTypesBundle\ActionBarType;
99
use Shopsys\FormTypesBundle\YesNoType;
1010
use Shopsys\FrameworkBundle\Form\ColorPickerType;
11-
use Shopsys\FrameworkBundle\Form\DatePickerType;
11+
use Shopsys\FrameworkBundle\Form\DateTimeType;
1212
use Shopsys\FrameworkBundle\Form\DomainType;
1313
use Shopsys\FrameworkBundle\Form\GroupType;
1414
use Shopsys\FrameworkBundle\Form\ImageUploadType;
@@ -66,14 +66,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6666
]),
6767
],
6868
])
69-
->add('validityFrom', DatePickerType::class, [
69+
->add('validityFrom', DateTimeType::class, [
7070
'required' => false,
7171
'label' => t('Valid from'),
7272
'attr' => [
7373
'autocomplete' => 'off',
7474
],
7575
])
76-
->add('validityTo', DatePickerType::class, [
76+
->add('validityTo', DateTimeType::class, [
7777
'required' => false,
7878
'label' => t('Valid to'),
7979
'attr' => [

src/Model/NotificationBar/NotificationBarFacade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\ORM\QueryBuilder;
99
use Shopsys\FrameworkBundle\Component\Image\ImageFacade;
10+
use Shopsys\FrameworkBundle\Component\Redis\CleanStorefrontCacheFacade;
1011

1112
class NotificationBarFacade
1213
{
@@ -15,12 +16,14 @@ class NotificationBarFacade
1516
* @param \Shopsys\FrameworkBundle\Model\NotificationBar\NotificationBarRepository $notificationBarRepository
1617
* @param \Shopsys\FrameworkBundle\Component\Image\ImageFacade $imageFacade
1718
* @param \Shopsys\FrameworkBundle\Model\NotificationBar\NotificationBarFactory $notificationBarFactory
19+
* @param \Shopsys\FrameworkBundle\Component\Redis\CleanStorefrontCacheFacade $cleanStorefrontCacheFacade
1820
*/
1921
public function __construct(
2022
protected readonly EntityManagerInterface $em,
2123
protected readonly NotificationBarRepository $notificationBarRepository,
2224
protected readonly ImageFacade $imageFacade,
2325
protected readonly NotificationBarFactory $notificationBarFactory,
26+
protected readonly CleanStorefrontCacheFacade $cleanStorefrontCacheFacade,
2427
) {
2528
}
2629

@@ -35,6 +38,8 @@ public function create(NotificationBarData $notificationBarData): void
3538
$this->em->flush();
3639

3740
$this->imageFacade->manageImages($notificationBar, $notificationBarData->image);
41+
42+
$this->cleanStorefrontCacheFacade->cleanStorefrontGraphqlQueryCache(CleanStorefrontCacheFacade::NOTIFICATION_BARS_QUERY_KEY_PART);
3843
}
3944

4045
/**
@@ -50,6 +55,8 @@ public function edit(NotificationBar $notificationBar, NotificationBarData $noti
5055

5156
$this->imageFacade->manageImages($notificationBar, $notificationBarData->image);
5257

58+
$this->cleanStorefrontCacheFacade->cleanStorefrontGraphqlQueryCache(CleanStorefrontCacheFacade::NOTIFICATION_BARS_QUERY_KEY_PART);
59+
5360
return $notificationBar;
5461
}
5562

@@ -62,6 +69,8 @@ public function delete(int $notificationBarId): void
6269

6370
$this->em->remove($notificationBar);
6471
$this->em->flush();
72+
73+
$this->cleanStorefrontCacheFacade->cleanStorefrontGraphqlQueryCache(CleanStorefrontCacheFacade::NOTIFICATION_BARS_QUERY_KEY_PART);
6574
}
6675

6776
/**

src/Model/NotificationBar/NotificationBarRepository.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,13 @@ public function getById(int $notificationBarId): NotificationBar
5050
*/
5151
public function findVisibleAndValidByDomainId(int $domainId): ?array
5252
{
53-
$dateTodayMidnight = new DateTime();
54-
$dateTodayMidnight = $dateTodayMidnight->format('Y-m-d 00:00:00');
55-
5653
return $this->getAllByDomainIdQueryBuilder($domainId)
5754
->andWhere('nb.validityFrom IS NULL OR nb.validityFrom <= :now')
5855
->andWhere('nb.validityTo IS NULL OR nb.validityTo >= :now')
5956
->andWhere('nb.hidden = FALSE')
6057
->setParameters([
6158
'domainId' => $domainId,
62-
'now' => $dateTodayMidnight,
59+
'now' => new DateTime(),
6360
])
6461
->getQuery()->execute();
6562
}

src/Resources/views/Admin/Content/NotificationBar/listGrid.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
{% block grid_value_cell_id_validityFrom %}
1212
{% if value is not null %}
13-
{{ value|formatDate }}
13+
{{ value|formatDateTime }}
1414
{% else %}
1515
{{ 'Unlimited'|trans }}
1616
{% endif %}
1717
{% endblock %}
1818

1919
{% block grid_value_cell_id_validityTo %}
2020
{% if value is not null %}
21-
{{ value|formatDate }}
21+
{{ value|formatDateTime }}
2222
{% else %}
2323
{{ 'Unlimited'|trans }}
2424
{% endif %}

0 commit comments

Comments
 (0)