I created a payment method and added 2 fields vendor name and vendor voucher and save field in the database using observer.
It's working fine. Now, I want this to show additional information in the order view payment information section.
Any help please on how to do it.
Thanks
-
do you want to show in admin or frontend?– Amit NaraniwalCommented Feb 19, 2019 at 11:38
-
currently in admin its save from fornt end in addtional_informaton– 3434Commented Feb 19, 2019 at 11:39
-
a:3:{s:14:"voucher_number";s:5:"23423";s:11:"vendor_name";s:6:"werwrw";s:12:"method_title";s:16:"Training Vssoucher";} like that– 3434Commented Feb 19, 2019 at 11:39
1 Answer
I guess you are talking about payment additional information.
Assuming you have the actual order object in the variable $order
you can get the complete array of additional information with the following code:
$additionalInformation = $order->getPayment()->getAdditionalInformation();
If you are in quote context, there is a similar way. Again I assume that your actual quote is in the variable $quote
:
$additionalInformation = $quote->getPayment()->getAdditionalInformation();
Update: In case the returned data is not an array, it might be necessary to unserialize it like follows:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$serializer = $objectManager->get('\Magento\Framework\Serialize\Serializer\Serialize');
$additionalInformationArray = $serializer->unserialize($additionalInformation);
//after this you can access it by key like this:
echo $additionalInformationArray['voucher_number'];
echo $additionalInformationArray['vendor_name'];
....
I hope that helps.
-
{s:14:"voucher_number";s:5:"23423";s:11:"vendor_name";s:6:"werwrw";s:12:"method_title";s:16:"Training Vssoucher";} i am getting like that after your code now i want voucher_number and vendor name form here;)– 3434Commented Feb 19, 2019 at 12:46
-
I hope the complete output you get is
a:3:{s:14:"voucher_number";s:5:"23423";s:11:"vendor_name";s:6:"werwrw";s:12:"method_title";s:18:"Training Vssoucher";}
that would be a correct serialized array. I update my answer– HelgeBCommented Feb 19, 2019 at 13:10