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