From 4ab5cc297df0d42284e665c29e2899585861582d Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Mon, 2 Sep 2024 14:30:32 +0200 Subject: [PATCH] hyva checkout fee calculation --- Block/Totals/Fee.php | 34 +------------------ .../layout/hyva_checkout_components.xml | 6 ++-- .../templates/total-segments/fee.phtml | 10 +++--- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/Block/Totals/Fee.php b/Block/Totals/Fee.php index 06c612d..0c2e5d7 100644 --- a/Block/Totals/Fee.php +++ b/Block/Totals/Fee.php @@ -39,39 +39,7 @@ public function getTitle(): string ->getPayment(); return $this->feeHelper->getBuckarooPaymentFeeLabel($payment->getMethod()); } catch (\Throwable $th) { - return __('Fee'); + return __('Payment Fee'); } } - - /** - * Get total from array of data - * - * @return float - */ - public function getTotal(): float - { - $totalData = $this->getSegment(); - if (false === is_array($totalData)) { - throw new \UnexpectedValueException('Expecting an array but getting '.gettype($totalData)); - } - - $extensionAttributes = $totalData['extension_attributes']; - - if ( - is_array($extensionAttributes) && - isset($extensionAttributes['buckaroo_fee']) && - is_scalar($extensionAttributes['buckaroo_fee']) - ) { - return floatval($extensionAttributes['buckaroo_fee']); - } - - if ($extensionAttributes instanceof \Magento\Quote\Api\Data\TotalSegmentExtension) { - /** @var \Magento\Quote\Api\Data\TotalSegmentExtension $extensionAttributes */ - if ($extensionAttributes->getBuckarooFee() !== null) { - return $extensionAttributes->getBuckarooFee(); - } - } - - return 0; - } } diff --git a/view/frontend/layout/hyva_checkout_components.xml b/view/frontend/layout/hyva_checkout_components.xml index 69f5457..3292516 100644 --- a/view/frontend/layout/hyva_checkout_components.xml +++ b/view/frontend/layout/hyva_checkout_components.xml @@ -202,9 +202,9 @@ - - \ No newline at end of file + diff --git a/view/frontend/templates/total-segments/fee.phtml b/view/frontend/templates/total-segments/fee.phtml index 77923b8..b00a1fa 100644 --- a/view/frontend/templates/total-segments/fee.phtml +++ b/view/frontend/templates/total-segments/fee.phtml @@ -14,14 +14,16 @@ use Hyva\Checkout\ViewModel\Checkout\Formatter as FormatterViewModel; use Hyva\Theme\Model\ViewModelRegistry; $formatterViewModel = $viewModels->require(FormatterViewModel::class); -$total = $block->getTotal(); -if ($total != 0) { +$segment = $block->getSegment(); +if ($segment['value'] != 0) { ?>
- + escapeHtml($block->getTitle()) ?> - currency($total ?? 0) ?> + + currency($segment['value'] ?? 0) ?> +