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.

48 lines
1.2KB

  1. <?php
  2. namespace common\logic\Order\ProductOrder;
  3. use common\logic\BaseService;
  4. use common\logic\BuilderInterface;
  5. use common\logic\PointSale\PointSale\PointSale;
  6. use common\logic\Product\Product\ProductSolver;
  7. use common\logic\User\User\User;
  8. use common\logic\User\UserProducer\UserProducer;
  9. class ProductOrderBuilder extends BaseService implements BuilderInterface
  10. {
  11. protected ProductSolver $productSolver;
  12. public function __construct()
  13. {
  14. $this->productSolver = $this->loadService(ProductSolver::class);
  15. }
  16. public function instanciate(): ProductOrder
  17. {
  18. $productOrder = new ProductOrder();
  19. return $productOrder;
  20. }
  21. public function updatePrice(
  22. ProductOrder $productOrder,
  23. User $user = null,
  24. UserProducer $userProducer = null,
  25. PointSale $pointSale = null,
  26. int $quantity = 1)
  27. {
  28. $productOrder->price = $this->productSolver->getPrice(
  29. $productOrder->product,
  30. [
  31. 'user' => $user,
  32. 'user_producer' => $userProducer,
  33. 'point_sale' => $pointSale,
  34. 'quantity' => $quantity
  35. ]);
  36. $productOrder->save();
  37. return $productOrder;
  38. }
  39. }