-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Add Magento Discount to order lines
- Loading branch information
1 parent
96fdc1f
commit 16f4313
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Order\Lines\Generator; | ||
|
||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Mollie\Api\Types\OrderLineType; | ||
use Mollie\Payment\Helper\General; | ||
|
||
class MagentoDiscount implements GeneratorInterface | ||
{ | ||
/** | ||
* @var General | ||
*/ | ||
private $mollieHelper; | ||
|
||
public function __construct( | ||
General $mollieHelper | ||
) { | ||
$this->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; | ||
} | ||
} |
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