public function __construct(Order $order, DTOBuilderFactoryInterface $dtoBuilderFactory) { $this->entity = $order; $this->dtoBuilderFactory = $dtoBuilderFactory; $this->entityDTO = $this->getEntityDTO(); $this->setId(); $this->setTime(); $this->entityDTO->referenceNumber = $this->entity->getReferenceNumber(); $this->entityDTO->externalId = $this->entity->getExternalId(); $this->entityDTO->totalItems = $this->entity->totalItems(); $this->entityDTO->totalQuantity = $this->entity->totalQuantity(); $this->entityDTO->discountNames = $this->entity->getDiscountNames(); $this->entityDTO->status = $this->dtoBuilderFactory->getOrderStatusTypeDTOBuilder($this->entity->getStatus())->build(); if ($this->entity->getShippingAddress() !== null) { $this->entityDTO->shippingAddress = $this->dtoBuilderFactory->getOrderAddressDTOBuilder($this->entity->getShippingAddress())->build(); } if ($this->entity->getBillingAddress() !== null) { $this->entityDTO->billingAddress = $this->dtoBuilderFactory->getOrderAddressDTOBuilder($this->entity->getBillingAddress())->build(); } if ($this->entity->getTotal() !== null) { $this->entityDTO->total = $this->dtoBuilderFactory->getCartTotalDTOBuilder($this->entity->getTotal())->withAllData()->build(); } if ($this->entity->getShipmentRate() !== null) { $this->entityDTO->shipmentRate = $this->dtoBuilderFactory->getShipmentRateDTOBuilder($this->entity->getShipmentRate())->build(); } if ($this->entity->getTaxRate() !== null) { $this->entityDTO->taxRate = $this->dtoBuilderFactory->getTaxRateDTOBuilder($this->entity->getTaxRate())->build(); } foreach ($this->entity->getShipments() as $shipment) { $this->entityDTO->shipments[] = $this->dtoBuilderFactory->getShipmentDTOBuilder($shipment)->build(); } }
public function testCreateDefaults() { $order = new Order(); $this->assertTrue($order->getId() instanceof UuidInterface); $this->assertTrue($order->getCreated() instanceof DateTime); $this->assertSame(null, $order->getExternalId()); $this->assertSame(null, $order->getReferenceNumber()); $this->assertSame('0.0.0.0', $order->getIp4()); $this->assertSame(0, $order->totalItems()); $this->assertSame(0, $order->totalQuantity()); $this->assertTrue($order->getStatus()->isPending()); $this->assertSame(null, $order->getTotal()); $this->assertSame(null, $order->getShippingAddress()); $this->assertSame(null, $order->getBillingAddress()); $this->assertSame(null, $order->getUser()); $this->assertSame(null, $order->getShipmentRate()); $this->assertSame(null, $order->getTaxRate()); $this->assertSame(null, $order->getOrderItem(0)); $this->assertSame(0, count($order->getOrderItems())); $this->assertSame(0, count($order->getCoupons())); $this->assertSame(0, count($order->getPayments())); $this->assertSame(0, count($order->getProducts())); $this->assertSame(0, count($order->getShipments())); }