@@ -54,8 +54,13 @@ public function create(array $options = []): CatalogPromotionInterface
5454 $ catalogPromotion = $ this ->catalogPromotionFactory ->createNew ();
5555 $ catalogPromotion ->setCode ($ options ['code ' ]);
5656 $ catalogPromotion ->setName ($ options ['name ' ]);
57- $ catalogPromotion ->setStartDate ($ options ['startDate ' ]);
58- $ catalogPromotion ->setEndDate ($ options ['endDate ' ]);
57+ if (isset ($ options ['start_date ' ])) {
58+ $ catalogPromotion ->setStartDate ($ this ->getDate ($ options ['start_date ' ]));
59+ }
60+ if (isset ($ options ['end_date ' ])) {
61+ $ catalogPromotion ->setEndDate ($ this ->getDate ($ options ['end_date ' ]));
62+ }
63+
5964 $ catalogPromotion ->setEnabled ($ options ['enabled ' ]);
6065 $ catalogPromotion ->setPriority ($ options ['priority ' ] ?? 0 );
6166 $ catalogPromotion ->setExclusive ($ options ['exclusive ' ] ?? false );
@@ -96,28 +101,17 @@ public function create(array $options = []): CatalogPromotionInterface
96101 protected function configureOptions (OptionsResolver $ resolver ): void
97102 {
98103 $ resolver
99- ->setDefault ('code ' , function (Options $ options ): string {
100- return StringInflector::nameToCode ($ options ['name ' ]);
101- })
104+ ->setDefault ('code ' , fn (Options $ options ): string => StringInflector::nameToCode ($ options ['name ' ]))
102105 ->setNormalizer ('code ' , static function (Options $ options , ?string $ code ): string {
103106 if ($ code === null ) {
104107 return StringInflector::nameToCode ($ options ['name ' ]);
105108 }
106109
107110 return $ code ;
108111 })
109- ->setDefault ('name ' , function (Options $ options ): string {
110- /** @var string $words */
111- $ words = $ this ->faker ->words (3 , true );
112-
113- return $ words ;
114- })
115- ->setDefault ('label ' , function (Options $ options ): string {
116- return $ options ['name ' ];
117- })
118- ->setDefault ('description ' , function (Options $ options ): string {
119- return $ this ->faker ->sentence ();
120- })
112+ ->setDefault ('name ' , fn (Options $ options ): string => (string ) $ this ->faker ->words (3 , true ))
113+ ->setDefault ('label ' , fn (Options $ options ): string => $ options ['name ' ])
114+ ->setDefault ('description ' , fn (Options $ options ): string => $ this ->faker ->sentence ())
121115 ->setDefault ('channels ' , LazyOption::all ($ this ->channelRepository ))
122116 ->setAllowedTypes ('channels ' , 'array ' )
123117 ->setNormalizer ('channels ' , LazyOption::findBy ($ this ->channelRepository , 'code ' ))
@@ -127,10 +121,10 @@ protected function configureOptions(OptionsResolver $resolver): void
127121 ->setAllowedTypes ('priority ' , ['integer ' , 'null ' ])
128122 ->setDefault ('exclusive ' , false )
129123 ->setAllowedTypes ('exclusive ' , ['boolean ' , 'null ' ])
130- ->setDefault ('startDate ' , null )
131- ->setAllowedTypes ('startDate ' , [\DateTimeInterface::class, 'null ' ])
132- ->setDefault ('endDate ' , null )
133- ->setAllowedTypes ('endDate ' , [\DateTimeInterface::class, 'null ' ])
124+ ->setDefault ('start_date ' , null )
125+ ->setAllowedTypes ('start_date ' , [\DateTimeInterface::class, ' string ' , 'null ' ])
126+ ->setDefault ('end_date ' , null )
127+ ->setAllowedTypes ('end_date ' , [\DateTimeInterface::class, ' string ' , 'null ' ])
134128 ->setDefault ('enabled ' , true )
135129 ->setAllowedTypes ('enabled ' , 'boolean ' )
136130 ;
@@ -144,4 +138,13 @@ private function getLocales(): iterable
144138 yield $ locale ->getCode ();
145139 }
146140 }
141+
142+ private function getDate (\DateTimeInterface |string $ date ): \DateTimeInterface
143+ {
144+ if ($ date instanceof \DateTimeInterface) {
145+ return $ date ;
146+ }
147+
148+ return new \DateTime ($ date );
149+ }
147150}
0 commit comments