diff --git a/Service/Order/Lines/Generator/MagentoDiscount.php b/Service/Order/Lines/Generator/MagentoDiscount.php new file mode 100644 index 00000000000..8ff514fa923 --- /dev/null +++ b/Service/Order/Lines/Generator/MagentoDiscount.php @@ -0,0 +1,46 @@ +mollieHelper = $mollieHelper; + } + + public function process(OrderInterface $order, array $orderLines): array + { + if (!$order->getBaseDiscountAmount()) { + return $orderLines; + } + + $forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId()); + $currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode(); + $amount = (float)$order->getData(($forceBaseCurrency ? 'base_' : '') . 'discount_amount'); + + $orderLines[] = [ + 'type' => OrderLineType::TYPE_DISCOUNT, + 'name' => __('Magento Discount'), + 'quantity' => 1, + 'unitPrice' => $this->mollieHelper->getAmountArray($currency, $amount), + 'totalAmount' => $this->mollieHelper->getAmountArray($currency, $amount), + 'vatRate' => '0.00', + 'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0), + ]; + + return $orderLines; + } +} diff --git a/etc/di.xml b/etc/di.xml index 1349db4a581..ab71b0eed8d 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -158,6 +158,7 @@ + Mollie\Payment\Service\Order\Lines\Generator\MagentoDiscount Mollie\Payment\Service\Order\Lines\Generator\FoomanTotals Mollie\Payment\Service\Order\Lines\Generator\WeeeFeeGenerator Mollie\Payment\Service\Order\Lines\Generator\MageWorxRewardPoints