Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BP-3546-Use-object-as-array-in-Buckaroo-HyvaCheckout-Block-Totals-Fee-getTotal-22 #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions Block/Totals/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions view/frontend/layout/hyva_checkout_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +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"
<block name="price-summary.total-segment.buckaroo_fee_hyva"
class="Buckaroo\HyvaCheckout\Block\Totals\Fee"
as="buckaroo_fee"
as="buckaroo_fee_hyva"
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: 6 additions & 4 deletions view/frontend/templates/total-segments/fee.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
?>
<div class="flex gap-4 justify-between md:gap-0">
<span class="label font-bold">
<span class="label">
<?= $block->escapeHtml($block->getTitle()) ?>
</span>
<span class="value"><?= /* @noEscape */ $formatterViewModel->currency($total ?? 0) ?></span>
<span class="value">
<?= /* @noEscape */ $formatterViewModel->currency($segment['value'] ?? 0) ?>
</span>
</div>
<?php
}
Loading