3

How to add products link in magento2 sales=> order tab in admin panel? Also I want to add custom attribute to order grid in admin panel. for example want to add type(custom attribute) to admin panel sales=> order grid

More description: Login to admin panel, go to sales: order, open one of orders, you can see ordered items. I want to have item links and view products who ordered

also want to add one column in ordered items. want to show custom attribute like type or model in ordered items info

2
  • Please describe your question in detail, if possible with a screenshot. Commented Nov 23, 2019 at 4:39
  • @AshokDubariya Updated. thanks for your response
    – MGPM
    Commented Nov 23, 2019 at 5:48

2 Answers 2

3

app/code/Vendor/Module/view/adminhtml/layout/sales_order_view.xml

Introduced new custom_column and changed column_name block's template for product name with url

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <body>
        <referenceBlock name="order_items">
            <arguments>
                <argument name="columns" xsi:type="array">
                    <item name="custom_column" xsi:type="string" translate="true">custom column</item>
                </argument>
            </arguments>
            <referenceBlock name="default_order_items_renderer">
                <arguments>
                    <argument name="columns" xsi:type="array">
                        <item name="custom_column" xsi:type="string" translate="true">col-customcolumn</item>
                    </argument>
                </arguments>
            </referenceBlock>
            <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Vendor_Module::items/column/name.phtml" group="column"/>
            <block class="Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn"
                   name="column_custom_column"
                   template="Vendor_Module::items/column/custom_column.phtml" group="column" />
        </referenceBlock>
    </body>
</page>

app/code/Vendor/Module/view/adminhtml/templates/items/column/name.phtml

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

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @see \Magento\Sales\Block\Adminhtml\Items\Column\Name
 */
?>

<?php if ($_item = $block->getItem()): ?>
    <div id="order_item_<?= /* @escapeNotVerified */ $_item->getId() ?>_title"
         class="product-title">
         <!-- added product url -->
        <a href="<?= $_item->getProduct()->getProductUrl() ?>" target="_blank"><?= $block->escapeHtml($_item->getName()) ?></a>
    </div>

    <div class="product-sku-block">
        <span><?= /* @escapeNotVerified */ __('SKU') ?>:</span> <?= implode('<br />', $this->helper('Magento\Catalog\Helper\Data')->splitSku($block->escapeHtml($block->getSku()))) ?>
    </div>

    <?php if ($block->getOrderOptions()): ?>
        <dl class="item-options">
            <?php foreach ($block->getOrderOptions() as $_option): ?>
                <dt><?= /* @escapeNotVerified */ $_option['label'] ?>:</dt>
                <dd>
                    <?php if (isset($_option['custom_view']) && $_option['custom_view']): ?>
                        <?= /* @escapeNotVerified */ $block->getCustomizedOptionValue($_option) ?>
                    <?php else: ?>
                        <?php $_option = $block->getFormattedOption($_option['value']); ?>
                        <?= /* @escapeNotVerified */ $_option['value'] ?><?php if (isset($_option['remainder']) && $_option['remainder']): ?><span id="<?= /* @escapeNotVerified */ $_dots = 'dots' . uniqid() ?>"> ...</span><span id="<?= /* @escapeNotVerified */ $_id = 'id' . uniqid() ?>"><?= /* @escapeNotVerified */ $_option['remainder'] ?></span>
                            <script>
                                require(['prototype'], function() {
                                    $('<?= /* @escapeNotVerified */ $_id ?>').hide();
                                    $('<?= /* @escapeNotVerified */ $_id ?>').up().observe('mouseover', function(){$('<?= /* @escapeNotVerified */ $_id ?>').show();});
                                    $('<?= /* @escapeNotVerified */ $_id ?>').up().observe('mouseover', function(){$('<?= /* @escapeNotVerified */ $_dots ?>').hide();});
                                    $('<?= /* @escapeNotVerified */ $_id ?>').up().observe('mouseout',  function(){$('<?= /* @escapeNotVerified */ $_id ?>').hide();});
                                    $('<?= /* @escapeNotVerified */ $_id ?>').up().observe('mouseout',  function(){$('<?= /* @escapeNotVerified */ $_dots ?>').show();});
                                });
                            </script>
                        <?php endif; ?>
                    <?php endif; ?>
                </dd>
            <?php endforeach; ?>
        </dl>
    <?php endif; ?>
    <?= $block->escapeHtml($_item->getDescription()) ?>
<?php endif; ?>

app/code/Vendor/Module/view/adminhtml/templates/items/column/custom_column.phtml

you can get product attributes from here

$_item = $block->getItem();
$product = $block->getItem()->getProduct();
1
  • Use: <a target="_blank" href="<?= $block->getUrl('catalog/product/edit', ['id'=>$block->getItem()->getProduct()->getId()]) ?>">View Product</a> To add link to admin product page. Commented Aug 29, 2022 at 19:04
0

@Ranganathan Would it be possible to make the url point to the backend url

<a href="<backend_product_url>" target="_blank"><?= $block->escapeHtml($_item->getName()) ?></a>

Your Answer

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

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