Skip to content

Commit

Permalink
Revert "BP-3546-Use-object-as-array-in-Buckaroo-HyvaCheckout-Block-To…
Browse files Browse the repository at this point in the history
…tals-Fee-getTotal-22"

This reverts commit b3f8499.
  • Loading branch information
AlbinaBaraliu committed Aug 21, 2024
1 parent b3f8499 commit 634cdaa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
63 changes: 63 additions & 0 deletions Block/Totals/Fee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Buckaroo\HyvaCheckout\Block\Totals;

use Magento\Checkout\Model\Session as SessionCheckout;
use Buckaroo\Magento2\Helper\PaymentFee;
use Magento\Framework\View\Element\Template\Context;

class Fee extends \Magento\Framework\View\Element\Template
{
protected PaymentFee $feeHelper;

protected SessionCheckout $sessionCheckout;

public function __construct(
Context $context,
array $data,
PaymentFee $feeHelper,
SessionCheckout $sessionCheckout
)
{
parent::__construct($context, $data);
$this->feeHelper = $feeHelper;
$this->sessionCheckout = $sessionCheckout;
}

/**
* Get title based on payment method config
*
* @return string
*/
public function getTitle(): string
{
try {
$payment = $this->sessionCheckout
->getQuote()
->getPayment();
return $this->feeHelper->getBuckarooPaymentFeeLabel($payment->getMethod());
} catch (\Throwable $th) {
return __('Fee');
}
return __('Fee');
}

/**
* Get total from array of data
*
* @return float
*/
public function getTotal(): float
{
$totalData = $this->getSegment();
$extensionAttributes = $totalData['extension_attributes'] ?? null;
if (
$extensionAttributes
) {
return (floatval($extensionAttributes->getBuckarooFee()['buckaroo_fee'][0]));
}
return 0;
}
}
7 changes: 4 additions & 3 deletions view/frontend/layout/hyva_checkout_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@
<block name="price-summary.total-segment.pretax_buckaroo_fee"
as="pretax_buckaroo_fee"
template="Buckaroo_HyvaCheckout::total-segments/empty.phtml"/>
<block name="price-summary.total-segment.buckaroo_fee_hyva"
as="buckaroo_fee_hyva"
<block name="price-summary.total-segment.buckaroo_fee"
class="Buckaroo\HyvaCheckout\Block\Totals\Fee"
as="buckaroo_fee"
template="Buckaroo_HyvaCheckout::total-segments/fee.phtml"/>
<block name="price-summary.total-segment.buckaroo_already_paid"
class="Buckaroo\HyvaCheckout\Block\Totals\AlreadyPaid"
as="buckaroo_already_paid"
template="Buckaroo_HyvaCheckout::total-segments/already-paid.phtml"/>
</referenceBlock>
</body>
</page>
</page>
10 changes: 4 additions & 6 deletions view/frontend/templates/total-segments/fee.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ use Hyva\Checkout\ViewModel\Checkout\Formatter as FormatterViewModel;
use Hyva\Theme\Model\ViewModelRegistry;

$formatterViewModel = $viewModels->require(FormatterViewModel::class);
$total = $block->getSegment();

if ($total['value'] != 0) {

$total = $block->getTotal();
if ($total != 0) {
?>
<div class="flex gap-4 justify-between md:gap-0">
<span class="label font-bold">
<?= $block->escapeHtml($total['title']) ?>
<?= $block->escapeHtml($block->getTitle()) ?>
</span>
<span class="value"><?= /* @noEscape */ $formatterViewModel->currency($total['value'] ?? 0) ?></span>
<span class="value"><?= /* @noEscape */ $formatterViewModel->currency($total ?? 0) ?></span>
</div>
<?php
}

0 comments on commit 634cdaa

Please sign in to comment.