2

In the backend, click on sales -> orders -> view once, and under the information tab, there is a "Items Ordered" option. Add a product link to the SKU of the product below, which links to the frontend product. As shown in the following figure:

enter image description here If anyone could provide some guidance, I would greatly appreciate it. Thank you.

1 Answer 1

2

Create file app/code/Tarun/StackOverflow/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Tarun_StackOverflow" >
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

Create file app/code/Tarun/StackOverflow/registration.php

<?php
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Tarun_StackOverflow', __DIR__);

Create file app/code/Tarun/StackOverflow/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="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="left">
            <referenceBlock name="column_name" template="Tarun_StackOverflow::items/column/name.phtml" />
        </referenceContainer>
    </body>
</page>

Create file app/code/Tarun/StackOverflow/view/adminhtml/templates/items/column/name.phtml

<?php
/**
 * @var $block \Magento\Sales\Block\Adminhtml\Items\Column\Name
 * @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
 */
?>

<?php
/** @var \Magento\Catalog\Helper\Data $catalogHelper */
$catalogHelper = $block->getData('catalogHelper');
?>
<?php if ($_item = $block->getItem()): ?>
    <div id="order_item_<?= (int) $_item->getId() ?>_title"
         class="product-title">
        <?= $block->escapeHtml($_item->getName()) ?>
    </div>
    <div class="product-sku-block">
        <span><?= $block->escapeHtml(__('SKU'))?>:</span>
        <a target="_blank" href="<?= $_item->getProduct()->getProductUrl(); ?>"> <?= /* @noEscape */ implode('<br />', $catalogHelper->splitSku($block->escapeHtml($block->getSku()))) ?></a>
    </div>

    <?php if ($block->getOrderOptions()): ?>
        <dl class="item-options">
            <?php foreach ($block->getOrderOptions() as $_option): ?>
                <dt><?= $block->escapeHtml($_option['label']) ?>:</dt>
                <dd>
                    <?php if (isset($_option['custom_view']) && $_option['custom_view']): ?>
                        <?= /* @noEscape */ $block->getCustomizedOptionValue($_option) ?>
                    <?php else: ?>
                        <?php $_option = $block->getFormattedOption($_option['value']); ?>
                        <?php $dots = 'dots' . uniqid(); ?>
                        <?php $id = 'id' . uniqid(); ?>
                        <?= $block->escapeHtml($_option['value'], ['a', 'br']) ?>
                        <?php if (isset($_option['remainder']) && $_option['remainder']): ?>
                            <span id="<?= /* @noEscape */ $dots; ?>"> ...</span>
                            <span id="<?= /* @noEscape */ $id; ?>">
                                <?= $block->escapeHtml($_option['remainder'], ['a']) ?>
                            </span>
                            <?php $scriptString = <<<script
                                require(['prototype'], function() {

script;
                            $scriptString .= "$('" . /* @noEscape */ $id . "').hide();" . PHP_EOL;
                            $scriptString .= "$('" . /* @noEscape */ $id .
                                "').up().observe('mouseover', function(){ $('" . /* @noEscape */ $id . "').show();});" .
                                PHP_EOL;
                            $scriptString .= "$('" . /* @noEscape */ $id .
                                "').up().observe('mouseover', function(){ $('" . /* @noEscape */ $dots .
                                "').hide();});" . PHP_EOL;
                            $scriptString .= "$('" . /* @noEscape */ $id .
                                "').up().observe('mouseout',  function(){ $('" . /* @noEscape */ $id .
                                "').hide();});" . PHP_EOL;
                            $scriptString .= "$('" . /* @noEscape */ $id .
                                "').up().observe('mouseout',  function(){ $('" . /* @noEscape */ $dots .
                                "').show();});" . PHP_EOL . "});" . PHP_EOL;
                            ?>
                            <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
                        <?php endif; ?>
                    <?php endif; ?>
                </dd>
            <?php endforeach; ?>
        </dl>
    <?php endif; ?>
    <?= $block->escapeHtml($_item->getDescription()) ?>
<?php endif; ?>

Result enter image description here

If this answer works as your expected, please mark it as accepted. That indicates your issue is solved and makes it easier for others with the same issue to find a verified answer. And that would be great if you click the upvote button for the answer in case you feel it is useful.

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.