0

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

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

1 Answer 1

1

In totals.phtml file :-

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

$order = $block->getOrder();
$rewardPoint = $order->getRewardPoint();
4
  • its working, :) Jan 8, 2020 at 6:53
  • can you please explain me little bit about your answer Jan 8, 2020 at 6:54
  • 1
    in this file module-sales/Block/Order/Totals.php around line no. 73 Jan 8, 2020 at 6:56
  • 1
    you are find this function getOrder() so simply you can use this function,, :) Jan 8, 2020 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.