Created
April 8, 2024 09:36
-
-
Save Frank-Magmodules/b905ba1843be64d26746c08729a2e627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Service/Order/Lines/Generator/MagentoRewardPoints.php b/Service/Order/Lines/Generator/MagentoRewardPoints.php | |
new file mode 100644 | |
index 00000000..66513849 | |
--- /dev/null | |
+++ b/Service/Order/Lines/Generator/MagentoRewardPoints.php | |
@@ -0,0 +1,55 @@ | |
+<?php | |
+ | |
+declare(strict_types=1); | |
+ | |
+namespace Mollie\Payment\Service\Order\Lines\Generator; | |
+ | |
+use Magento\Sales\Api\Data\OrderInterface; | |
+use Mollie\Payment\Helper\General; | |
+ | |
+class MagentoRewardPoints implements GeneratorInterface | |
+{ | |
+ /** | |
+ * @var General | |
+ */ | |
+ private $mollieHelper; | |
+ | |
+ public function __construct( | |
+ General $mollieHelper | |
+ ) { | |
+ $this->mollieHelper = $mollieHelper; | |
+ } | |
+ | |
+ public function process(OrderInterface $order, array $orderLines): array | |
+ { | |
+ $extensionAttributes = $order->getExtensionAttributes(); | |
+ | |
+ if (!method_exists($extensionAttributes, 'getRewardCurrencyAmount')) { | |
+ return $orderLines; | |
+ } | |
+ | |
+ $amount = $extensionAttributes->getRewardCurrencyAmount(); | |
+ if ($amount === null) { | |
+ return $orderLines; | |
+ } | |
+ | |
+ $forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId()); | |
+ if ($forceBaseCurrency) { | |
+ $amount = $extensionAttributes->getBaseRewardCurrencyAmount(); | |
+ } | |
+ | |
+ $currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode(); | |
+ | |
+ $orderLines[] = [ | |
+ 'type' => 'surcharge', | |
+ 'name' => 'Reward Points', | |
+ 'quantity' => 1, | |
+ 'unitPrice' => $this->mollieHelper->getAmountArray($currency, -$amount), | |
+ 'totalAmount' => $this->mollieHelper->getAmountArray($currency, -$amount), | |
+ 'vatRate' => 0, | |
+ 'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0.0), | |
+ ]; | |
+ | |
+ return $orderLines; | |
+ } | |
+} | |
diff --git a/Service/Order/Lines/OrderLinesProcessor.php b/Service/Order/Lines/OrderLinesProcessor.php | |
index 5f760c3d..746585e1 100644 | |
--- a/Service/Order/Lines/OrderLinesProcessor.php | |
+++ b/Service/Order/Lines/OrderLinesProcessor.php | |
@@ -23,13 +23,7 @@ public function __construct( | |
$this->processors = $processors; | |
} | |
- /** | |
- * @param array $orderLine | |
- * @param OrderInterface $order | |
- * @param OrderItemInterface|null $orderItem | |
- * @return array | |
- */ | |
- public function process(array $orderLine, OrderInterface $order, OrderItemInterface $orderItem = null) | |
+ public function process(array $orderLine, OrderInterface $order, OrderItemInterface $orderItem = null): array | |
{ | |
foreach ($this->processors as $processor) { | |
$orderLine = $processor->process($orderLine, $order, $orderItem); | |
@@ -37,4 +31,4 @@ public function process(array $orderLine, OrderInterface $order, OrderItemInterf | |
return $orderLine; | |
} | |
-} | |
\ No newline at end of file | |
+} | |
diff --git a/etc/di.xml b/etc/di.xml | |
index 312a24c8..41a65097 100644 | |
--- a/etc/di.xml | |
+++ b/etc/di.xml | |
@@ -161,6 +161,7 @@ | |
<item name="magento_giftwrapping" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftWrapping</item> | |
<item name="geissweb_euvat" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\GeisswebEuvat</item> | |
<item name="cart_rule_discount" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\ShippingDiscount</item> | |
+ <item name="magento_reward_points" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MagentoRewardPoints</item> | |
</argument> | |
</arguments> | |
</type> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment