You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9KB

  1. <?php
  2. namespace common\logic\Order\ProductOrder;
  3. use common\logic\BaseService;
  4. use common\logic\BuilderInterface;
  5. use common\logic\Order\Order\Order;
  6. use common\logic\PointSale\PointSale\PointSale;
  7. use common\logic\Product\Product\ProductSolver;
  8. use common\logic\User\User\User;
  9. use common\logic\User\UserProducer\UserProducer;
  10. class ProductOrderBuilder extends BaseService implements BuilderInterface
  11. {
  12. protected ProductSolver $productSolver;
  13. public function __construct()
  14. {
  15. $this->productSolver = $this->loadService(ProductSolver::class);
  16. }
  17. public function instanciate(): ProductOrder
  18. {
  19. $productOrder = new ProductOrder();
  20. return $productOrder;
  21. }
  22. public function updatePrice(
  23. ProductOrder $productOrder,
  24. User $user = null,
  25. UserProducer $userProducer = null,
  26. PointSale $pointSale = null,
  27. int $quantity = 1)
  28. {
  29. $productOrder->price = $this->productSolver->getPrice(
  30. $productOrder->product,
  31. [
  32. 'user' => $user,
  33. 'user_producer' => $userProducer,
  34. 'point_sale' => $pointSale,
  35. 'quantity' => $quantity
  36. ]);
  37. $productOrder->save();
  38. return $productOrder;
  39. }
  40. public function updateInvoicePrice(ProductOrder $productOrder, array $params = []): void
  41. {
  42. $productOrder->invoice_price = $this->productSolver->getPrice($productOrder->product, [
  43. 'user' => isset($params['user']) ?? null,
  44. 'user_producer' => isset($params['user_producer']) ?? null,
  45. 'point_sale' => isset($params['point_sale']) ?? null,
  46. 'quantity' => $productOrder->quantity
  47. ]);
  48. $productOrder->save();
  49. }
  50. public function deleteByOrder(Order $order): void
  51. {
  52. ProductOrder::deleteAll(['id_order' => $order->id]);
  53. }
  54. }