/** * Method testNoPrecision */ public function testNoPrecision() { $this->roundingService->expects($this->never())->method('round'); $lineItemManager = new LineItemManager($this->roundingService); $product = $this->getProductEntityWithPrecision('kg', 3); $quantity = $this->getRandomQuantity(); $roundedQuantity = $lineItemManager->roundProductQuantity($product, 'unit', $quantity); $this->assertEquals($quantity, $roundedQuantity); }
/** * @param FormEvent $event */ public function preSubmit(FormEvent $event) { /** @var LineItem $lineItem */ $lineItem = $event->getForm()->getData(); $data = $event->getData(); $product = $lineItem->getProduct(); if (!$product instanceof Product && !empty($data['product'])) { /** @var ProductRepository $repository */ $repository = $this->registry->getManagerForClass($this->productClass)->getRepository($this->productClass); /** @var Product $product */ $product = $repository->find((int) $data['product']); } if (!$product || empty($data['unit']) || empty($data['quantity'])) { return; } $roundedQuantity = $this->lineItemManager->roundProductQuantity($product, $data['unit'], $data['quantity']); $data['quantity'] = $roundedQuantity; $event->setData($data); }