1717use Doctrine \ORM \EntityManagerInterface ;
1818use Sylius \Behat \Service \SharedStorageInterface ;
1919use Sylius \Bundle \CoreBundle \Fixture \Factory \ExampleFactoryInterface ;
20+ use Sylius \Component \Channel \Repository \ChannelRepositoryInterface ;
2021use Sylius \Component \Core \Formatter \StringInflector ;
2122use Sylius \Component \Core \Model \CatalogPromotionInterface ;
2223use Sylius \Component \Core \Model \CatalogPromotionRuleInterface ;
@@ -35,19 +36,23 @@ final class CatalogPromotionContext implements Context
3536
3637 private EntityManagerInterface $ entityManager ;
3738
39+ private ChannelRepositoryInterface $ channelRepository ;
40+
3841 private SharedStorageInterface $ sharedStorage ;
3942
4043 public function __construct (
4144 ExampleFactoryInterface $ catalogPromotionExampleFactory ,
4245 FactoryInterface $ catalogPromotionRuleFactory ,
4346 FactoryInterface $ catalogPromotionActionFactory ,
4447 EntityManagerInterface $ entityManager ,
48+ ChannelRepositoryInterface $ channelRepository ,
4549 SharedStorageInterface $ sharedStorage
4650 ) {
4751 $ this ->catalogPromotionExampleFactory = $ catalogPromotionExampleFactory ;
4852 $ this ->catalogPromotionRuleFactory = $ catalogPromotionRuleFactory ;
4953 $ this ->catalogPromotionActionFactory = $ catalogPromotionActionFactory ;
5054 $ this ->entityManager = $ entityManager ;
55+ $ this ->channelRepository = $ channelRepository ;
5156 $ this ->sharedStorage = $ sharedStorage ;
5257 }
5358
@@ -172,6 +177,19 @@ public function thereIsACatalogPromotionAvailableInChannelThatReducesPriceByAndA
172177 $ this ->entityManager ->flush ();
173178 }
174179
180+ /**
181+ * @When And the :catalogPromotion catalog promotion is no longer available
182+ */
183+ public function theAdministratorMakesThisCatalogPromotionUnavailableInTheChannel (
184+ CatalogPromotionInterface $ catalogPromotion
185+ ): void {
186+ foreach ($ this ->channelRepository ->findAll () as $ channel ) {
187+ $ catalogPromotion ->removeChannel ($ channel );
188+ }
189+ $ this ->entityManager ->persist ($ catalogPromotion );
190+ $ this ->entityManager ->flush ();
191+ }
192+
175193 private function createCatalogPromotion (
176194 string $ name ,
177195 ?string $ code = null ,
0 commit comments