diff --git a/src/Model/Order/Item/OrderItemData.php b/src/Model/Order/Item/OrderItemData.php index 46ee9ae7fc..5edc3c327f 100644 --- a/src/Model/Order/Item/OrderItemData.php +++ b/src/Model/Order/Item/OrderItemData.php @@ -125,4 +125,17 @@ public function getUnitPrice(): Price { return new Price($this->unitPriceWithoutVat, $this->unitPriceWithVat); } + + /** + * @return string|null + */ + public function getItemUuid(): ?string + { + return match ($this->type) { + OrderItemTypeEnum::TYPE_PRODUCT => $this->product->getUuid(), + OrderItemTypeEnum::TYPE_TRANSPORT => $this->transport->getUuid(), + OrderItemTypeEnum::TYPE_PAYMENT => $this->payment->getUuid(), + default => null, + }; + } } diff --git a/src/Model/Order/Item/OrderItemFactory.php b/src/Model/Order/Item/OrderItemFactory.php index 6d9735aee4..088cd47983 100644 --- a/src/Model/Order/Item/OrderItemFactory.php +++ b/src/Model/Order/Item/OrderItemFactory.php @@ -32,7 +32,7 @@ public function createOrderItem( ): OrderItem { $entityClassName = $this->entityNameResolver->resolve(OrderItem::class); - return new $entityClassName( + $orderItem = new $entityClassName( $order, $orderItemData->name, new Price($orderItemData->unitPriceWithoutVat, $orderItemData->unitPriceWithVat), @@ -42,6 +42,12 @@ public function createOrderItem( $orderItemData->unitName, $orderItemData->catnum, ); + + if ($orderItemData->usePriceCalculation === false && $orderItemData->totalPriceWithVat !== null) { + $orderItem->setTotalPrice(new Price($orderItemData->totalPriceWithoutVat, $orderItemData->totalPriceWithVat)); + } + + return $orderItem; } /** diff --git a/src/Model/Payment/Payment.php b/src/Model/Payment/Payment.php index ac1b29ffc5..89fd29c243 100644 --- a/src/Model/Payment/Payment.php +++ b/src/Model/Payment/Payment.php @@ -15,6 +15,7 @@ use Shopsys\FrameworkBundle\Model\Localization\AbstractTranslatableEntity; use Shopsys\FrameworkBundle\Model\Payment\Exception\PaymentDomainNotFoundException; use Shopsys\FrameworkBundle\Model\Payment\Exception\PaymentPriceNotFoundException; +use Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat; use Shopsys\FrameworkBundle\Model\Transport\Transport; /** @@ -506,4 +507,13 @@ public function isGatewayPayment(): bool { return in_array($this->type, $this->getGatewayPayments(), true); } + + /** + * @param int $domainId + * @return \Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat + */ + public function getVatForDomain(int $domainId): Vat + { + return $this->getPaymentDomain($domainId)->getVat(); + } } diff --git a/src/Model/Transport/Transport.php b/src/Model/Transport/Transport.php index 6b3b24898d..bb3169e6d8 100644 --- a/src/Model/Transport/Transport.php +++ b/src/Model/Transport/Transport.php @@ -14,6 +14,7 @@ use Shopsys\FrameworkBundle\Component\Grid\Ordering\OrderableEntityInterface; use Shopsys\FrameworkBundle\Model\Localization\AbstractTranslatableEntity; use Shopsys\FrameworkBundle\Model\Payment\Payment; +use Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat; use Shopsys\FrameworkBundle\Model\Transport\Exception\TransportDomainNotFoundException; use Shopsys\FrameworkBundle\Model\Transport\Exception\TransportPriceNotFoundException; @@ -452,4 +453,13 @@ public function getType() { return $this->type; } + + /** + * @param int $domainId + * @return \Shopsys\FrameworkBundle\Model\Pricing\Vat\Vat + */ + public function getVatForDomain(int $domainId): Vat + { + return $this->getTransportDomain($domainId)->getVat(); + } }