$block is not working in override phtml file
-
28-03-2021 - |
Question
I override totals.phtml, but when I am calling my custom block in it, its not working.
File path:
Magento/vendor/magento/module-sales/view/adminhtml/templates/order/totals.phtml
Override File path:
SimpleMagento/RewardPoint/view/adminhtml/templates/order/totals.phtml
File: sales_order_view.xml
<body>
<referenceBlock name="order_totals">
<action method="setTemplate">
<argument name="template" translate="true" xsi:type="string">SimpleMagento_RewardPoint::order/totals.phtml</argument>
</action>
</referenceBlock>
</body>
Override totals.phtml:
/* @var \SimpleMagento\RewardPoint\Block\Sales\Order\ShowReward $block */
?>
<table class="data-table admin__table-secondary order-subtotal-table">
<td class="label"><strong>Customer's Reward Point:</strong></td>
<td><?php $getValue = $block->getReward(); ?>
<strong> <?= $getValue ?></strong>
</td>
$getVaue displays null, however, I when I change in sales_order_view.xml
<referenceContainer name="order_additional_info">
<block class="SimpleMagento\RewardPoint\Block\Sales\Order\ShowReward" name="sales_order_view_custom" template="order/view/custom.phtml" />
</referenceContainer>
File: ShowReward.php
FilePath:
SimpleMagento\RewardPoint\Block\Sales\Order\ShowReward
public function getReward(){
$id = $this->getRequest()->getParam('order_id');
$getOrder = $this->factory->create()->load($id);
return $getOrder['reward_point'];
}
and its displayed value perfectly, but its not showing in order totals
box, so I override totals.phtml
Solution
In totals.phtml
file :-
/* @var \Magento\Sales\Block\Adminhtml\Order\Totals $block */
$order = $block->getOrder();
$rewardPoint = $order->getRewardPoint();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange