1

I'm super noob in Magento module development, but I'm working on a custom payment module that grabs some payment information on checkout into "additional_information", using this Observer:

class DataAssignObserver extends AbstractDataAssignObserver
{
    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        $method = $this->readMethodArgument($observer);
        $data = $this->readDataArgument($observer);

        $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
        if (!is_array($additionalData)) {
            return;
        }

        // $paymentModel = $this->readPaymentModelArgument($observer);  // Magento 2.1 ONLY
        $paymentInfo = $method->getInfoInstance();

        // $paymentModel->setAdditionalInformation(
        $paymentInfo->setAdditionalInformation(
            $additionalData
        );
    }
}

Is there a detailed example on how to pull this information into the Order information pages, admin and customer side?

I know a few bits and pieces, like $paymentInfo->getAdditionalInformation(), but I'd really like to have a detailed example for it.

  • do you want to show the additional information on order page(adminhtml)? – Bojjaiah Feb 21 '17 at 9:39
  • Yes, adminhtml and frontend – Marco Ferreira Feb 22 '17 at 19:06
  • which place do you want to show? – Bojjaiah Feb 23 '17 at 4:56
  • Well, ideally to the "Payment Information" on the adminhtml side and "Payment Method" on the frontend side. Basically the same way you get credit card information when you use credit card. – Marco Ferreira Feb 24 '17 at 5:14
  • see example magento.stackexchange.com/questions/76434/… – Bojjaiah Feb 24 '17 at 6:51
0

you can pull the information by extending Payment Method Block.

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[VendorName]_[ModuleName]',
    __DIR__
);

Info.php

<?php

namespace [VendorName]\[ModuleName]\Block\Adminhtml\Order\View\Tab;

class Info extends  \Magento\Sales\Block\Adminhtml\Order\View\Tab\Info{



}

etc/adminhtml/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" type="[VendorName]\[ModuleName]\Block\Adminhtml\Order\View\Tab\Info" />
</config>

view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="order_tab_info">
            <action method="setTemplate">
                <argument name="template" translate="true" xsi:type="string">order/view/tab/Info.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

view/adminhtml/templates/order/view/tab/Info.phtml

    <?php
    /**
     * Copyright © 2016 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */

    // @codingStandardsIgnoreFile

    ?>
    <?php /** @var $block \Magento\Sales\Block\Adminhtml\Order\View\Tab\Info */ ?>
    <?php $_order = $block->getOrder() ?>

    <div id="order-messages">
        <?php echo $block->getChildHtml('order_messages') ?>
    </div>

    <?php echo $block->getChildHtml('order_info') ?>
    <input type="hidden" name="order_id" value="<?php /* @escapeNotVerified */ echo $_order->getId() ?>"/>

    <section class="admin__page-section order-view-billing-shipping">
        <div class="admin__page-section-title">
            <span class="title"><?php /* @escapeNotVerified */ echo __('Payment &amp; Shipping Method') ?></span>
        </div>
<!-- this is Sample Text -->
        <h1>Magento 2 Custom Payment Text</h1>
        <div class="admin__page-section-content">
            <div class="admin__page-section-item order-payment-method<?php if ($_order->getIsVirtual()): ?> order-payment-method-virtual<?php endif; ?>">
                <?php /* Payment Method */ ?>
                <div class="admin__page-section-item-title">
                    <span class="title"><?php /* @escapeNotVerified */ echo __('Payment Information') ?></span>
                </div>
                <div class="admin__page-section-item-content">
                    <div class="order-payment-method-title"><?php echo $block->getPaymentHtml() ?></div>
                    <div class="order-payment-currency"><?php /* @escapeNotVerified */ echo __('The order was placed using %1.', $_order->getOrderCurrencyCode()) ?></div>
                    <div class="order-payment-additional">
                        <?php echo $block->getChildHtml('order_payment_additional'); ?>
                        <?php echo $block->getChildHtml('payment_additional_info'); ?>
                    </div>
                </div>
            </div>
            <?php echo $block->getChildHtml('order_shipping_view') ?>
        </div>
    </section>

    <?php echo $block->getGiftOptionsHtml() ?>

    <section class="admin__page-section">
        <div class="admin__page-section-title">
            <span class="title"><?php /* @escapeNotVerified */ echo __('Items Ordered') ?></span>
        </div>
        <?php echo $block->getItemsHtml() ?>
    </section>

    <section class="admin__page-section">
        <div class="admin__page-section-title">
            <span class="title"><?php /* @escapeNotVerified */ echo __('Order Total') ?></span>
        </div>
        <div class="admin__page-section-content">
            <div class="admin__page-section-item order-comments-history">
                <div class="admin__page-section-item-title">
                    <span class="title"><?php /* @escapeNotVerified */ echo __('Notes for this Order') ?></span>
                </div>
                <?php echo $block->getChildHtml('order_history') ?>
            </div>

            <div class="admin__page-section-item order-totals">
                <div class="admin__page-section-item-title">
                    <span class="title"><?php /* @escapeNotVerified */ echo __('Order Totals') ?></span>
                </div>
                <?php echo $block->getChildHtml('order_totals') ?>
            </div>
        </div>
    </section>

    <?php echo $block->getChildHtml('popup_window');?>

    <script>
        require([
            "prototype",
            "Magento_Sales/order/giftoptions_tooltip"
        ], function(){

    //<![CDATA[
            /**
             * Retrieve gift options tooltip content
             */
            function getGiftOptionsTooltipContent(itemId) {
                var contentLines = [];
                var headerLine = null;
                var contentLine = null;

                $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
                    if (element.down(0)) {
                        headerLine = element.down(0).innerHTML;
                        contentLine = element.down(0).next().innerHTML;
                        if (contentLine.length > 30) {
                            contentLine = contentLine.slice(0,30) + '...';
                        }
                        contentLines.push(headerLine + ' ' + contentLine);
                    }
                });
                return contentLines.join('<br/>');
            }
            giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
            window.getGiftOptionsTooltipContent = getGiftOptionsTooltipContent;
    //]]>

        });
    </script>

By this way you can override the Payment Section.

  • Thank you. I'll try this out tonight and give some feedback. – Marco Ferreira Feb 28 '17 at 20:35
  • Sorry, but only now I could get back to this. Three issues I'm having: 1. After following the sample code/files you posted I got the excepption ReflectionException: Class [...]\Block\Adminhtml\Order\View\Tab\Info does not exist. 2. Removing <preference for="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" type="[...]\Block\Adminhtml\Order\View\Tab\Info" /> from etc/adminhtml/di.xml fixed the exception, but the order info page is empty. 3. Finally, in Info.php, I already have a namespace defined as namespace [VendorName]\[ModuleName]\Block;. How would I go about these? – Marco Ferreira May 7 '17 at 14:59
0

Add vendor_name in view/adminhtml/layout/sales_order_view.xml

vendor_name::order/view/tab/Info.phtml

This solve the blank page in order info.

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.