productSolver = $this->loadService(ProductSolver::class); } public function instanciate(Order $order, Product $product, float $quantity, float $price): ProductOrder { $productOrder = new ProductOrder(); $productOrder->populateOrder($order); $productOrder->populateProduct($product); $productOrder->populateTaxRate($product->taxRate); $productOrder->quantity = $quantity; $productOrder->price = $price; $productOrder->unit = $product->unit; $productOrder->step = $product->step; return $productOrder; } public function create(Order $order, Product $product, float $quantity, float $price): ProductOrder { $productOrder = $this->instanciate($order, $product, $quantity, $price); $productOrder->save(); return $productOrder; } public function updatePrice( ProductOrder $productOrder, User $user = null, UserProducer $userProducer = null, PointSale $pointSale = null, int $quantity = 1) { $productOrder->price = $this->productSolver->getPrice( $productOrder->product, [ 'user' => $user, 'user_producer' => $userProducer, 'point_sale' => $pointSale, 'quantity' => $quantity ]); $productOrder->save(); return $productOrder; } public function updateInvoicePrice(ProductOrder $productOrder, array $params = []): void { $productOrder->invoice_price = $this->productSolver->getPrice($productOrder->product, [ 'user' => isset($params['user']) ?? null, 'user_producer' => isset($params['user_producer']) ?? null, 'point_sale' => isset($params['point_sale']) ?? null, 'quantity' => $productOrder->quantity ]); $productOrder->save(); } public function deleteByOrder(Order $order): void { ProductOrder::deleteAll(['id_order' => $order->id]); } }