|
- <?php
-
- namespace common\logic\Order\ProductOrder;
-
- use common\logic\BaseService;
- use common\logic\BuilderInterface;
- use common\logic\Order\Order\Order;
- 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;
- }
-
- 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]);
- }
- }
|