2

I created reward_point in the sales_order table, whenever someone purchased a few points stored in that field.

Now I need to display that point into the admin order view page, I already override sales_order_view and create the block, but failed to get the value of the reward point in view page.

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>

ShowReward.php

class ShowReward extends \Magento\Sales\Block\Adminhtml\Order\Totals
{
   public function _initTotals(){

    $this->_totals['reward_point'] = new \Magento\Framework\DataObject(
        [
            'code' => 'reward_point',
            'strong' => true,
            'value' => $this->getSource()->getReward(),
            'label' => __('Reward Point'),
            'area' => 'footer',
        ]
    );
    return $this;
   }
}

for the value of the reward_point I have override Order.php, which similarly look like:

public function getReward()
{
    return $this->getData(OrderInterface::reward_point);
}

but for that, I have to override OrderInterface, any other way to achieve this functionality?

4
  • 1
    please screenshot which position you need to add display.. Commented Jan 7, 2020 at 10:15
  • @RkRathod, I am trying to add into total orders box Commented Jan 7, 2020 at 10:23
  • drive.google.com/file/d/1Dg8Kf3JQWfGkmM7DahISojb1ZWwqeI8J/… here is the screenshot of it, Admin>Sales>Order>View>Information tab and Order totals box Commented Jan 7, 2020 at 10:25
  • but I am giving more important currently fetch data into block rather than position of my block in frontend Commented Jan 7, 2020 at 10:25

3 Answers 3

3

You can try below code in your block, it might be helpful to get Reward point custom field value.

protected $orderRepository;

public function __construct(
 \Magento\Sales\Model\OrderRepository $orderRepository
) {
   $this->orderRepository = $orderRepository;
}

public function getReward()
{
   $order_id = $this->getRequest()->getParam('order_id');
   $order =  $this->orderRepository->get($order_id);
   return $order->getRewardPoint(); // your reward point
}
2
  • Thanks I just did that :) Commented Jan 7, 2020 at 11:02
  • if possible can you please let me how can I place my block below Total Orders box Commented Jan 7, 2020 at 11:02
0

Other way is

protected $factory;

public function __construct(Context $context,
                            OrderFactory $factory,
                            array $data = [])
{
    parent::__construct($context, $data);
    $this->factory = $factory;
}

public function getReward(){
    $id = $this->getRequest()->getParam('order_id');
    $getOrder = $this->factory->create()->load($id);
    return $getOrder['reward_point'];
}
0

protected $orderRepository;

public function __construct( \Magento\Sales\Model\OrderRepository $orderRepository ) { $this->orderRepository = $orderRepository; }

public function getReward() { $order_id = $this->getRequest()->getParam('order_id'); $order = $this->orderRepository->get($order_id); return $order->getRewardPoint(); // your reward point }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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