2

I want to add extra 2 columns into braintree settlement report after Existing Report Columns currently we have override braintree_report.xml file & show extra columns but load information after filter the report

First column as payment method from sales_order_payment table

Second column as credit card type from sales_order_payment table

Can we help me how to load the extra columns information?

0

we have created custom module & created below files.

app/code/Namespace/Module/view/adminhtml/ui_component/braintree_report.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="braintree_report_columns">
        <column name="creditCardType" class="Namespace\Module\Ui\Component\Report\Listing\Column\CreditCardType">
            <settings>
                <dataType>text</dataType>
                <label translate="true">Credit Card Type</label>
            </settings>
        </column>
</columns>
</listing>

app/code/Namespace/Module/Ui/Component/Report/Listing/Column/CreditCardType.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
Namespace\Module\Ui\Component\Report\Listing\Column;

use \Magento\Framework\View\Element\UiComponent\ContextInterface;
use \Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
use \Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Braintree\Model\Adapter\BraintreeAdapterFactory;
use Magento\Braintree\Model\Adapter\BraintreeSearchAdapter;

/**
 * Class CreditCardType
 */
class CreditCardType extends Column
{
    protected $_searchCriteria;

    private $braintreeAdapterFactory;
    /**
     * @var BraintreeSearchAdapter
     */
    private $braintreeSearchAdapter;

    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        BraintreeAdapterFactory $braintreeAdapterFactory,
        BraintreeSearchAdapter $braintreeSearchAdapter,
        SearchCriteriaBuilder $criteria,
        array $components = [],
        array $data = []
    )
    {
        $this->braintreeAdapterFactory = $braintreeAdapterFactory;
        $this->braintreeSearchAdapter = $braintreeSearchAdapter;
        $this->_searchCriteria  = $criteria;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    public function prepareDataSource(array $dataSource)
    {

        if (isset($dataSource['data']['items'])) {

            foreach ($dataSource['data']['items'] as & $item) {

                $transactionId=$item['id'];
                $braintreeAdapter = $this->braintreeAdapterFactory->create();
                $collection = $braintreeAdapter->search([$this->braintreeSearchAdapter->id()->is($transactionId)]);

                $item[$this->getData('name')] = $collection->firstItem()->creditCard['cardType'];

            }
        }
        return $dataSource;
    }

}

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.