I override totals.phtml, but when I am calling my custom block in it, its not working.

File path:


Override File path:


File: sales_order_view.xml

    <referenceBlock name="order_totals">
        <action method="setTemplate">
            <argument name="template" translate="true" xsi:type="string">SimpleMagento_RewardPoint::order/totals.phtml</argument>

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>

$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" />

File: ShowReward.php



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

| improve this question | | | | |
  • post your getReward() function – Rk Rathod Jan 8 at 6:29
  • @RkRathod I updated the question, As I mentioned block is working perfectly in my other phtml file – Sagar Parikh SGR Jan 8 at 6:33
  • in order object you can directly get the value so you dont want to create this function – Rk Rathod Jan 8 at 6:34
  • I did not understand, what you are trying to say – Sagar Parikh SGR Jan 8 at 6:37
  • you get the reward point value in order object like this $order->getRewardPoint(); or $order->getData('reward_point')?? – Rk Rathod Jan 8 at 6:38

In totals.phtml file :-

/* @var \Magento\Sales\Block\Adminhtml\Order\Totals $block */

$order = $block->getOrder();
$rewardPoint = $order->getRewardPoint();
| improve this answer | | | | |
  • its working, :) – Sagar Parikh SGR Jan 8 at 6:53
  • can you please explain me little bit about your answer – Sagar Parikh SGR Jan 8 at 6:54
  • 1
    in this file module-sales/Block/Order/Totals.php around line no. 73 – Rk Rathod Jan 8 at 6:56
  • 1
    you are find this function getOrder() so simply you can use this function,, :) – Rk Rathod Jan 8 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.