I want to display one text area, just after payment method list, on checkout page.
- Text area value should be saved on place order.
- Saved value also need to be displayed in Admin >> sales >> order >> view >> payment method.
In which table should I add the custom columns, so the values can be easily displayed on the admin-side.
UPDATE
I have displayed text-area to checkout step, How to save value on place order?
Thanks
Best Answer
At first, you must not add any custom columns to existing core tables, if you need you should create own tables.
I see at least two possible solutions:
additional_data
before place order request, or read data from the request in the observer. After that, you need to addpaymentInfoKeys
for all existing payment methods (a plugin might be useful) - http://devdocs.magento.com/guides/v2.1/payments-integrations/base-integration/payment-option-config.html. Now, all custom fields will be displayed in payment method details.Create own table for custom fields and use extension attributes to store custom fields for payment method. In that case, you also need to retrieve custom data in the observer but store it in the extension attributes, as an example - https://github.com/magento/magento2/blob/develop/app/code/Magento/Vault/Observer/AfterPaymentSaveObserver.php (in your case it will retrieve data from the request or
additional_data
, store in custom table and set to the extension attributes) and you need an additional plugin to load extension attributes - https://github.com/magento/magento2/blob/develop/app/code/Magento/Vault/Plugin/PaymentVaultAttributesLoad.php (reads from custom table and set to extension attributes). The final step is to create a block and provide own layout to render custom data.<referenceBlock name="order_additional_info"> <block class="BlockClassName" name="custom_name" template="BlockClassName::template_name.phtml"/> </referenceBlock>
The
order_additonal_info
will be available starting from 2.2.0 release but you can usepayment_additional_info
ororder_payment_additional
.Again, I see at least few solutions:
additional_data
and you can update it before place order but you need to prevent defaultplaceOrder
function for each payment method - https://github.com/magento/magento2/blob/develop/app/code/Magento/Checkout/view/frontend/web/js/view/payment/default.js#L129.afterPlaceOrder
(https://github.com/magento/magento2/blob/develop/app/code/Magento/Checkout/view/frontend/web/js/view/payment/default.js#L48) callback to send own request with custom fields.