Skip to content

Commit

Permalink
[CatalogPromotion] fix service typo, stateMachine error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Oct 22, 2021
1 parent bb8772d commit e116388
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function clear(): void
$catalogPromotions = $this->catalogPromotionRepository->findByCodes($appliedPromotionsCodes);
foreach ($catalogPromotions as $catalogPromotion) {
$stateMachine = $this->stateMachine->get($catalogPromotion, CatalogPromotionTransitions::GRAPH);
$stateMachine->apply(CatalogPromotionTransitions::TRANSITION_DEACTIVATE);
if ($stateMachine->can(CatalogPromotionTransitions::TRANSITION_DEACTIVATE)) {
$stateMachine->apply(CatalogPromotionTransitions::TRANSITION_DEACTIVATE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<tag name="messenger.message_handler" bus="sylius.event_bus" />
</service>

<service id="Sylius\Bundle\CoreBundle\Listener\FailedMessageListener">
<service id="Sylius\Bundle\CoreBundle\Listener\CatalogPromotionUpdateFailedMessageListener">
<argument type="service" id="sylius.event_bus" />
<tag name="kernel.event_listener" event="Symfony\Component\Messenger\Event\WorkerMessageFailedEvent" method="onMessageFailed" />
</service>
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function filterQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder

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

Expand Down
4 changes: 2 additions & 2 deletions tests/DataFixtures/ORM/resources/catalog_promotions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Sylius\Component\Core\Model\CatalogPromotion:
name: Sale1
enabled: true
start_date: "<(new \\DateTime('2021-10-12 00:00:00'))>"
end_date: "<(new \\DateTime('2021-10-12 23:59:59'))>"
end_date: "<(new \\DateTime('2021-10-12 23:59:58'))>"
state: inactive
sale_2:
code: sale2
name: Sale2
enabled: true
start_date: "<(new \\DateTime('2021-10-12 00:00:01'))>"
end_date: "<(new \\DateTime('2021-10-12 23:59:59'))>"
end_date: "<(new \\DateTime('2021-10-12 23:59:58'))>"
state: inactive
sale_3:
code: sale3
Expand Down
29 changes: 29 additions & 0 deletions tests/Functional/EligibleCatalogPromotionsProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,33 @@ public function it_provides_catalog_promotions_with_precision_to_seconds(): void

unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
}

/** @test */
public function it_provides_catalog_promotions_with_precision_to_seconds_for_end_date(): void
{
/** @var EligibleCatalogPromotionsProvider $eligibleCatalogPromotionsProvider */
$eligibleCatalogPromotionsProvider = self::$container->get('Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProviderInterface');

file_put_contents(self::$kernel->getProjectDir() . '/var/temporaryDate.txt', '2021-10-12 23:59:58');

$dateRangeCriteria = self::$container->get('sylius.catalog_promotion.criteria.date_range');

$eligibleCatalogPromotions = $eligibleCatalogPromotionsProvider->provide([$dateRangeCriteria]);

$expectedDateTimes = [
new \DateTime('2021-10-12 23:59:59'),
new \DateTime('2021-10-12 23:59:59'),
];

$actualDateTimes = [];

/** @var CatalogPromotionInterface $eligibleCatalogPromotion */
foreach ($eligibleCatalogPromotions as $eligibleCatalogPromotion) {
$actualDateTimes[] = $eligibleCatalogPromotion->getEndDate();
}

$this->assertTrue(($expectedDateTimes == $actualDateTimes));

unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
}
}

0 comments on commit e116388

Please sign in to comment.