Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
44 | */ |
||
45 | public function consumeEvent(TransformEvent $event): void |
||
46 | { |
||
47 | $this->buildProperty($event, ProductInterface::class, |
||
48 | function (ProductInterface $product, Document $document): void { |
||
49 | $soldUnits = 0; |
||
50 | |||
51 | foreach ($product->getVariants() as $productVariant) { |
||
52 | $soldUnits += count($this->orderItemRepository->findBy(['variant' => $productVariant])); |
||
53 | } |
||
54 | |||
55 | $document->set($this->soldUnitsProperty, $soldUnits); |
||
56 | } |
||
57 | ); |
||
58 | } |
||
59 | } |
||
60 |