Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class OrderService
- {
- private $itemService;
- public function __construct(ItemService $itemService)
- {
- $this->itemService = $itemService;
- }
- public function create(OrderCreationDto $context)
- {
- $order = new Order();
- $order->setCustomerId($context->customerId);
- $order->setPartnerId($context->partnerId);
- $order->setDeliveryAddress(new Address($context->address));
- $order->addItems($this->createOrderItems($context->products));
- return $order;
- }
- private function createOrderItems(array $products)
- {
- return array_map(function (array $product) {
- $item = $this->itemService->create($product->id, $product->price);
- $orderItem = new OrderItem();
- $orderItem->setItemId($item->getId());
- $orderItem->setProductId($product->id);
- return $orderItem;
- }, $products);
- }
- }
Add Comment
Please, Sign In to add comment