diff --git a/features/promotion/applying_catalog_promotions/reapplying_catalog_promotions_after_editing_its_action.feature b/features/promotion/applying_catalog_promotions/reapplying_catalog_promotions_after_editing_its_action.feature index 85dfb0a2f55..ff93efa0cb9 100644 --- a/features/promotion/applying_catalog_promotions/reapplying_catalog_promotions_after_editing_its_action.feature +++ b/features/promotion/applying_catalog_promotions/reapplying_catalog_promotions_after_editing_its_action.feature @@ -19,8 +19,8 @@ Feature: Reapplying catalog promotion after editing its action When I modify a catalog promotion "Summer sale" And I add action that gives "25%" percentage discount And I save my changes - Then the visitor view "Python T-Shirt" variant - And this product variant price should be "$7.50" + And the visitor view "Python T-Shirt" variant + Then this product variant price should be "$7.50" And this product original price should be "$10.00" @api @@ -28,8 +28,8 @@ Feature: Reapplying catalog promotion after editing its action When I modify a catalog promotion "Winter sale" And I edit its action so that it reduces price by "25%" And I save my changes - Then the visitor view "PHP T-Shirt" variant - And this product variant price should be "$15.00" + And the visitor view "PHP T-Shirt" variant + Then this product variant price should be "$15.00" And this product original price should be "$20.00" @api @@ -39,8 +39,8 @@ Feature: Reapplying catalog promotion after editing its action And I save my changes And I add action that gives "10%" percentage discount And I save my changes - Then the visitor view "PHP T-Shirt" variant - And this product variant price should be "$18.00" + And the visitor view "PHP T-Shirt" variant + Then this product variant price should be "$18.00" And this product original price should be "$20.00" @api @@ -48,8 +48,8 @@ Feature: Reapplying catalog promotion after editing its action When I modify a catalog promotion "Winter sale" And I add another action that gives "10%" percentage discount And I save my changes - Then the visitor view "PHP T-Shirt" variant - And this product variant price should be "$9.00" + And the visitor view "PHP T-Shirt" variant + Then this product variant price should be "$9.00" And this product original price should be "$20.00" @api @@ -57,6 +57,6 @@ Feature: Reapplying catalog promotion after editing its action When I modify a catalog promotion "Winter sale" And I remove its every action And I save my changes - Then the visitor view "PHP T-Shirt" variant - And the product variant price should be "$20.00" + And the visitor view "PHP T-Shirt" variant + Then the product variant price should be "$20.00" And the product original price should be "$20.00" diff --git a/src/Sylius/Bundle/ApiBundle/EventSubscriber/CatalogPromotionEventSubscriber.php b/src/Sylius/Bundle/ApiBundle/EventSubscriber/CatalogPromotionEventSubscriber.php index 8a2bfb787bf..f2c60d93a40 100644 --- a/src/Sylius/Bundle/ApiBundle/EventSubscriber/CatalogPromotionEventSubscriber.php +++ b/src/Sylius/Bundle/ApiBundle/EventSubscriber/CatalogPromotionEventSubscriber.php @@ -16,7 +16,6 @@ use ApiPlatform\Core\EventListener\EventPriorities; use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; -use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ViewEvent; @@ -42,17 +41,15 @@ public static function getSubscribedEvents(): array public function postWrite(ViewEvent $event): void { $entity = $event->getControllerResult(); + + if (!$entity instanceof CatalogPromotionInterface) { + return; + } + $method = $event->getRequest()->getMethod(); if ($method === Request::METHOD_PUT || $method === Request::METHOD_PATCH) { - if ($entity instanceof CatalogPromotionInterface) { - $this->eventBus->dispatch(new CatalogPromotionUpdated($entity->getCode())); - } - - if ($entity instanceof CatalogPromotionActionInterface) { - $this->eventBus->dispatch(new CatalogPromotionUpdated($entity->getCatalogPromotion()->getCode())); - } + $this->eventBus->dispatch(new CatalogPromotionUpdated($entity->getCode())); } } } - diff --git a/src/Sylius/Bundle/ApiBundle/spec/EventSubscriber/CatalogPromotionEventSubscriberSpec.php b/src/Sylius/Bundle/ApiBundle/spec/EventSubscriber/CatalogPromotionEventSubscriberSpec.php index 8040834d0f8..dee2cecd5f0 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/EventSubscriber/CatalogPromotionEventSubscriberSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/EventSubscriber/CatalogPromotionEventSubscriberSpec.php @@ -54,29 +54,6 @@ function it_dispatches_catalog_promotion_updated_after_writing_catalog_promotion )); } - function it_dispatches_catalog_promotion_updated_after_writing_catalog_promotion_action( - MessageBusInterface $eventBus, - CatalogPromotionActionInterface $catalogPromotionAction, - CatalogPromotionInterface $catalogPromotion, - HttpKernelInterface $kernel, - Request $request - ): void { - $request->getMethod()->willReturn(Request::METHOD_PUT); - - $catalogPromotionAction->getCatalogPromotion()->willReturn($catalogPromotion); - $catalogPromotion->getCode()->willReturn('Winter_sale'); - - $message = new CatalogPromotionUpdated('Winter_sale'); - $eventBus->dispatch($message)->willReturn(new Envelope($message))->shouldBeCalled(); - - $this->postWrite(new ViewEvent( - $kernel->getWrappedObject(), - $request->getWrappedObject(), - HttpKernelInterface::MASTER_REQUEST, - $catalogPromotionAction->getWrappedObject() - )); - } - function it_does_nothing_after_writing_other_entity( MessageBusInterface $eventBus, HttpKernelInterface $kernel, diff --git a/src/Sylius/Bundle/CoreBundle/Listener/CatalogPromotionUpdateListener.php b/src/Sylius/Bundle/CoreBundle/Listener/CatalogPromotionUpdateListener.php index 83e37e862da..46b90bcf5d9 100644 --- a/src/Sylius/Bundle/CoreBundle/Listener/CatalogPromotionUpdateListener.php +++ b/src/Sylius/Bundle/CoreBundle/Listener/CatalogPromotionUpdateListener.php @@ -14,24 +14,24 @@ namespace Sylius\Bundle\CoreBundle\Listener; use Doctrine\ORM\EntityManagerInterface; -use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionReprocessorInterface; +use Sylius\Bundle\CoreBundle\Processor\AllCatalogPromotionsProcessorInterface; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; use Sylius\Component\Resource\Repository\RepositoryInterface; final class CatalogPromotionUpdateListener { - private CatalogPromotionReprocessorInterface $catalogPromotionReprocessor; + private AllCatalogPromotionsProcessorInterface $catalogPromotionsProcessor; private RepositoryInterface $catalogPromotionRepository; private EntityManagerInterface $entityManager; public function __construct( - CatalogPromotionReprocessorInterface $catalogPromotionReprocessor, + AllCatalogPromotionsProcessorInterface $catalogPromotionsProcessor, RepositoryInterface $catalogPromotionRepository, EntityManagerInterface $entityManager ) { - $this->catalogPromotionReprocessor = $catalogPromotionReprocessor; + $this->catalogPromotionsProcessor = $catalogPromotionsProcessor; $this->catalogPromotionRepository = $catalogPromotionRepository; $this->entityManager = $entityManager; } @@ -42,7 +42,7 @@ public function __invoke(CatalogPromotionUpdated $event): void return; } - $this->catalogPromotionReprocessor->reprocess(); + $this->catalogPromotionsProcessor->process(); $this->entityManager->flush(); } diff --git a/src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessor.php b/src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessor.php similarity index 90% rename from src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessor.php rename to src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessor.php index 85fceb327fa..eafe326311b 100644 --- a/src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessor.php +++ b/src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessor.php @@ -15,7 +15,7 @@ use Sylius\Component\Resource\Repository\RepositoryInterface; -class CatalogPromotionReprocessor implements CatalogPromotionReprocessorInterface +final class AllCatalogPromotionsProcessor implements AllCatalogPromotionsProcessorInterface { private CatalogPromotionClearerInterface $catalogPromotionClearer; @@ -33,7 +33,7 @@ public function __construct( $this->catalogPromotionRepository = $catalogPromotionRepository; } - public function reprocess(): void + public function process(): void { $this->catalogPromotionClearer->clear(); diff --git a/src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessorInterface.php b/src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessorInterface.php similarity index 77% rename from src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessorInterface.php rename to src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessorInterface.php index 805ac490789..e2c34f29bfd 100644 --- a/src/Sylius/Bundle/CoreBundle/Processor/CatalogPromotionReprocessorInterface.php +++ b/src/Sylius/Bundle/CoreBundle/Processor/AllCatalogPromotionsProcessorInterface.php @@ -13,7 +13,7 @@ namespace Sylius\Bundle\CoreBundle\Processor; -interface CatalogPromotionReprocessorInterface +interface AllCatalogPromotionsProcessorInterface { - public function reprocess(): void; + public function process(): void; } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index c4f2227ce35..90ab647bd3a 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -277,8 +277,8 @@ diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/listeners.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/listeners.xml index 1143abb4cc9..56061046686 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/listeners.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/listeners.xml @@ -98,7 +98,7 @@ - + diff --git a/src/Sylius/Bundle/CoreBundle/spec/Listener/CatalogPromotionUpdateListenerSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Listener/CatalogPromotionUpdateListenerSpec.php index 6281d40df64..a044a30d126 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/Listener/CatalogPromotionUpdateListenerSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Listener/CatalogPromotionUpdateListenerSpec.php @@ -15,10 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; -use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionClearerInterface; -use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionProcessorInterface; -use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionReprocessorInterface; +use Sylius\Bundle\CoreBundle\Processor\AllCatalogPromotionsProcessorInterface; use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; use Sylius\Component\Resource\Repository\RepositoryInterface; @@ -26,7 +23,7 @@ final class CatalogPromotionUpdateListenerSpec extends ObjectBehavior { function let( - CatalogPromotionReprocessorInterface $catalogPromotionReprocessor, + AllCatalogPromotionsProcessorInterface $catalogPromotionReprocessor, RepositoryInterface $catalogPromotionRepository, EntityManagerInterface $entityManager ): void { @@ -38,14 +35,14 @@ function let( } function it_processes_catalog_promotion_that_has_just_been_updated( - CatalogPromotionReprocessorInterface $catalogPromotionReprocessor, + AllCatalogPromotionsProcessorInterface $catalogPromotionReprocessor, EntityManagerInterface $entityManager, RepositoryInterface $catalogPromotionRepository, CatalogPromotionInterface $catalogPromotion ): void { $catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn($catalogPromotion); - $catalogPromotionReprocessor->reprocess()->shouldBeCalled(); + $catalogPromotionReprocessor->process()->shouldBeCalled(); $entityManager->flush()->shouldBeCalled(); @@ -53,13 +50,13 @@ function it_processes_catalog_promotion_that_has_just_been_updated( } function it_does_nothing_if_there_is_not_catalog_promotion_with_given_code( - CatalogPromotionReprocessorInterface $catalogPromotionReprocessor, + AllCatalogPromotionsProcessorInterface $catalogPromotionReprocessor, RepositoryInterface $catalogPromotionRepository ): void { $catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn(null); $catalogPromotionRepository->findAll()->shouldNotBeCalled(); - $catalogPromotionReprocessor->reprocess()->shouldNotBeCalled(); + $catalogPromotionReprocessor->process()->shouldNotBeCalled(); $this->__invoke(new CatalogPromotionUpdated('WINTER_MUGS_SALE')); } diff --git a/src/Sylius/Bundle/CoreBundle/spec/Processor/CatalogPromotionReprocessorSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Processor/AllCatalogPromotionsProcessorSpec.php similarity index 91% rename from src/Sylius/Bundle/CoreBundle/spec/Processor/CatalogPromotionReprocessorSpec.php rename to src/Sylius/Bundle/CoreBundle/spec/Processor/AllCatalogPromotionsProcessorSpec.php index 4e3a9147f2b..b47ae2a9479 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/Processor/CatalogPromotionReprocessorSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Processor/AllCatalogPromotionsProcessorSpec.php @@ -19,7 +19,7 @@ use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; -class CatalogPromotionReprocessorSpec extends ObjectBehavior +final class AllCatalogPromotionsProcessorSpec extends ObjectBehavior { function let( CatalogPromotionClearerInterface $catalogPromotionClearer, @@ -33,7 +33,7 @@ function let( ); } - function it_should_clear_and_calculate_catalog_promotions( + function it_clears_and_processes_catalog_promotions( CatalogPromotionClearerInterface $catalogPromotionClearer, CatalogPromotionProcessorInterface $catalogPromotionProcessor, RepositoryInterface $catalogPromotionRepository, @@ -47,6 +47,6 @@ function it_should_clear_and_calculate_catalog_promotions( $catalogPromotionProcessor->process($firstCatalogPromotion)->shouldBeCalled(); $catalogPromotionProcessor->process($secondCatalogPromotion)->shouldBeCalled(); - $this->reprocess(); + $this->process(); } }