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?

| improve this question | | | | |
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
}
| improve this answer | | | | |
  • Thanks I just did that :) – Sagar Parikh SGR Jan 7 at 11:02
  • if possible can you please let me how can I place my block below Total Orders box – Sagar Parikh SGR Jan 7 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'];
}
| improve this answer | | | | |

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.