Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44a30a2

Browse files
committed
[CatalogPromotion] fix service typo, stateMachine error fixed
1 parent bb8772d commit 44a30a2

7 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionClearer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function clear(): void
5454
$catalogPromotions = $this->catalogPromotionRepository->findByCodes($appliedPromotionsCodes);
5555
foreach ($catalogPromotions as $catalogPromotion) {
5656
$stateMachine = $this->stateMachine->get($catalogPromotion, CatalogPromotionTransitions::GRAPH);
57-
$stateMachine->apply(CatalogPromotionTransitions::TRANSITION_DEACTIVATE);
57+
if ($stateMachine->can(CatalogPromotionTransitions::TRANSITION_DEACTIVATE)) {
58+
$stateMachine->apply(CatalogPromotionTransitions::TRANSITION_DEACTIVATE);
59+
}
5860
}
5961
}
6062

src/Sylius/Bundle/CoreBundle/Resources/config/services/listeners.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<tag name="messenger.message_handler" bus="sylius.event_bus" />
147147
</service>
148148

149-
<service id="Sylius\Bundle\CoreBundle\Listener\FailedMessageListener">
149+
<service id="Sylius\Bundle\CoreBundle\Listener\CatalogPromotionUpdateFailedMessageListener">
150150
<argument type="service" id="sylius.event_bus" />
151151
<tag name="kernel.event_listener" event="Symfony\Component\Messenger\Event\WorkerMessageFailedEvent" method="onMessageFailed" />
152152
</service>

src/Sylius/Bundle/CoreBundle/spec/Processor/CatalogPromotionClearerSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function it_clears_channel_pricings_with_catalog_promotions_applied(
6767
$catalogPromotionRepository->findByCodes(['winter_sale'])->willReturn([$catalogPromotion]);
6868

6969
$stateMachine->get($catalogPromotion, CatalogPromotionTransitions::GRAPH)->willReturn($stateMachineInterface);
70+
$stateMachineInterface->can(CatalogPromotionTransitions::TRANSITION_DEACTIVATE)->willReturn(true);
7071
$stateMachineInterface->apply(CatalogPromotionTransitions::TRANSITION_DEACTIVATE)->shouldBeCalled();
7172

7273
$this->clear();

src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function filterQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder
3131

3232
$queryBuilder
3333
->andWhere(sprintf('%s.startDate IS NULL OR %s.startDate <= :date', $root, $root))
34-
->andWhere(sprintf('%s.endDate IS NULL OR %s.endDate >= :date', $root, $root))
34+
->andWhere(sprintf('%s.endDate IS NULL OR %s.endDate > :date', $root, $root))
3535
->setParameter('date', $this->calendar->now())
3636
;
3737

src/Sylius/Bundle/PromotionBundle/spec/Criteria/DateRangeSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function it_adds_filters_to_query_builder(DateTimeProviderInterface $calendar, Q
3838
$calendar->now()->willReturn($now);
3939

4040
$queryBuilder->andWhere('o.startDate IS NULL OR o.startDate <= :date')->willReturn($queryBuilder)->shouldBeCalled();
41-
$queryBuilder->andWhere('o.endDate IS NULL OR o.endDate >= :date')->willReturn($queryBuilder)->shouldBeCalled();
41+
$queryBuilder->andWhere('o.endDate IS NULL OR o.endDate > :date')->willReturn($queryBuilder)->shouldBeCalled();
4242
$queryBuilder->setParameter('date', $now)->willReturn($queryBuilder)->shouldBeCalled();
4343

4444
$this->filterQueryBuilder($queryBuilder)->shouldReturn($queryBuilder);

tests/DataFixtures/ORM/resources/catalog_promotions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Sylius\Component\Core\Model\CatalogPromotion:
44
name: Sale1
55
enabled: true
66
start_date: "<(new \\DateTime('2021-10-12 00:00:00'))>"
7-
end_date: "<(new \\DateTime('2021-10-12 23:59:59'))>"
7+
end_date: "<(new \\DateTime('2021-10-12 23:59:58'))>"
88
state: inactive
99
sale_2:
1010
code: sale2
1111
name: Sale2
1212
enabled: true
1313
start_date: "<(new \\DateTime('2021-10-12 00:00:01'))>"
14-
end_date: "<(new \\DateTime('2021-10-12 23:59:59'))>"
14+
end_date: "<(new \\DateTime('2021-10-12 23:59:58'))>"
1515
state: inactive
1616
sale_3:
1717
code: sale3

tests/Functional/EligibleCatalogPromotionsProcessorTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,33 @@ public function it_provides_catalog_promotions_with_precision_to_seconds(): void
7070

7171
unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
7272
}
73+
74+
/** @test */
75+
public function it_provides_catalog_promotions_with_precision_to_seconds_for_end_date(): void
76+
{
77+
/** @var EligibleCatalogPromotionsProvider $eligibleCatalogPromotionsProvider */
78+
$eligibleCatalogPromotionsProvider = self::$container->get('Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProviderInterface');
79+
80+
file_put_contents(self::$kernel->getProjectDir() . '/var/temporaryDate.txt', '2021-10-12 23:59:58');
81+
82+
$dateRangeCriteria = self::$container->get('sylius.catalog_promotion.criteria.date_range');
83+
84+
$eligibleCatalogPromotions = $eligibleCatalogPromotionsProvider->provide([$dateRangeCriteria]);
85+
86+
$expectedDateTimes = [
87+
new \DateTime('2021-10-12 23:59:59'),
88+
new \DateTime('2021-10-12 23:59:59'),
89+
];
90+
91+
$actualDateTimes = [];
92+
93+
/** @var CatalogPromotionInterface $eligibleCatalogPromotion */
94+
foreach ($eligibleCatalogPromotions as $eligibleCatalogPromotion) {
95+
$actualDateTimes[] = $eligibleCatalogPromotion->getEndDate();
96+
}
97+
98+
$this->assertTrue(($expectedDateTimes == $actualDateTimes));
99+
100+
unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
101+
}
73102
}

0 commit comments

Comments
 (0)