|
- <?php
-
- namespace common\logic\Order\ProductOrder;
-
- use common\logic\BaseService;
- use common\logic\BuilderInterface;
- use common\logic\PointSale\PointSale\PointSale;
- use common\logic\Product\Product\ProductSolver;
- use common\logic\User\User\User;
- use common\logic\User\UserProducer\UserProducer;
-
- class ProductOrderBuilder extends BaseService implements BuilderInterface
- {
- protected ProductSolver $productSolver;
-
- public function __construct()
- {
- $this->productSolver = $this->loadService(ProductSolver::class);
- }
-
- public function instanciate(): ProductOrder
- {
- $productOrder = new ProductOrder();
-
- 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;
- }
- }
|