Skip to content

Commit

Permalink
Merge branch 'bugfix/reward-points' into release-week-15
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Apr 18, 2024
2 parents 4f7910f + 87209cf commit 4aaeeee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
55 changes: 55 additions & 0 deletions Service/Order/Lines/Generator/MagentoRewardPoints.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 2 additions & 8 deletions Service/Order/Lines/OrderLinesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ 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);
}

return $orderLine;
}
}
}
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 4aaeeee

Please sign in to comment.