3

when order placed at that time in admin sales order check that there is a gift option available or not if it is available that dispaly "yes" in order grid column else display "no".

please see attachments for more.

please share any suggestion if you have.

1) image where gift option available

gift option available here

2) image where display "yes" in grid enter image description here

thanks

1
  • Please check last comment of Answer... Jul 17, 2018 at 6:31

1 Answer 1

6

I created a UI component sales_order_grid.xml under

[Vendor]/[Module]/view/adminhtml/ui_component/sales_order_grid.xml

and add the following code to your sales_order_grid.xml:

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="sales_order_columns">
        <column name="export_status" class="[Vendor]\[Module]\Ui\Component\Listing\Column\Giftstatus">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">Gift Option</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Then created the UI class under

[Vendor]/[Module]/Ui/Component/Listing/Column/Giftstatus.php

add the following code to your Giftstatus.php:

<?php
namespace Vendor\Module\Ui\Component\Listing\Column;

use \Magento\Sales\Api\OrderRepositoryInterface;
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;

class Giftstatus extends Column
{
    protected $_orderRepository;
    protected $_searchCriteria;

    public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = [], array $data = [])
    {
        $this->_orderRepository = $orderRepository;
        $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) {

                $order  = $this->_orderRepository->get($item["entity_id"]);
                $status = $order->getData("gift_message_id");

                if($status){
                    $message = 'Yes';
                }
                else{
                    $message = 'No';
                }

                $item[$this->getData('name')] = $message;
            }
        }

        return $dataSource;
    }
}
11
  • Thanks for reply, i did the same but in result only get "No". i have changed "gift_message_id" to "gift_message_available" but not working it. Is there anything else need to change there ? Jul 12, 2018 at 5:49
  • Gift_message_id is only available if order contains gift message. Are you using gift option per order or per item? If using per order then it should work. Jul 12, 2018 at 6:02
  • Also check the sales_order table if your order contains the gift message id or not Jul 12, 2018 at 6:03
  • after var_dump() order data i got this name "gift_message_available" but his one is also not working. Jul 12, 2018 at 6:18
  • i am using gift option per order. Jul 12, 2018 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.