@@ -43,18 +43,12 @@ public function __construct(ConcatedNameResolverInterface $optionNameResolver, S
4343 /**
4444 * @param TransformEvent $event
4545 */
46- public function buildProperty (TransformEvent $ event ): void
46+ public function consumeEvent (TransformEvent $ event ): void
4747 {
48- /** @var ProductInterface $product */
49- $ product = $ event ->getObject ();
50-
51- if (!$ product instanceof ProductInterface) {
52- return ;
53- }
54-
55- $ document = $ event ->getDocument ();
56-
57- $ this ->resolveProductOptions ($ product , $ document );
48+ $ this ->buildProperty ($ event , ProductInterface::class,
49+ function (ProductInterface $ product , Document $ document ): void {
50+ $ this ->resolveProductOptions ($ product , $ document );
51+ });
5852 }
5953
6054 /**
@@ -67,16 +61,11 @@ private function resolveProductOptions(ProductInterface $product, Document $docu
6761 foreach ($ productVariant ->getOptionValues () as $ productOptionValue ) {
6862 $ optionCode = $ productOptionValue ->getOption ()->getCode ();
6963 $ index = $ this ->optionNameResolver ->resolvePropertyName ($ optionCode );
70-
71- if (!$ document ->has ($ index )) {
72- $ document ->set ($ index , []);
73- }
74-
75- $ reference = $ document ->get ($ index );
64+ $ options = $ document ->has ($ index ) ? $ document ->get ($ index ) : [];
7665 $ value = $ this ->stringFormatter ->formatToLowercaseWithoutSpaces ($ productOptionValue ->getValue ());
77- $ reference [] = $ value ;
66+ $ options [] = $ value ;
7867
79- $ document ->set ($ index , array_unique ($ reference ));
68+ $ document ->set ($ index , array_unique ($ options ));
8069 }
8170 }
8271 }
0 commit comments