0

I wan to get productUrl at backend side.

I am trying it by productrepository. I am getting right url at custom controller.

But when I'm trying it in import module's start controller I'm getting admin extra.

Like:

expected: www.example.com/catalog/product/view/id/9450/s/testProduct

Actualresult: www.example.com/adminBoard/catalog/product/view/id/9450/s/testProduct

I have already refer How to get product's frontend url from backend?

but not reached at solution.

8
  • Can you please upload your file code? Commented Dec 11, 2018 at 8:41
  • I have product id and product obj at backend how can i get frontend product url? @RohanHapani my code cannot help you Commented Dec 11, 2018 at 8:46
  • Please check my answer and let me know if not working. (use store code if require) Commented Dec 11, 2018 at 9:16
  • it's working in this controller but not working in \Magento\ImportExport\Controller\Adminhtml\Import\Start Commented Dec 11, 2018 at 9:18
  • okay. Let me check. Commented Dec 11, 2018 at 9:22

1 Answer 1

1

Try to use this below code :

<?php

namespace VendorName\ModuleName\Controller\Adminhtml\Index;

use Magento\Framework\Url;

class Index extends \Magento\Backend\App\Action
{
    protected $_url;

    public function __construct(
        ....
        \Magento\Backend\App\Action\Context $context,
        Url $url,
        ....
    ) {
        parent::__construct($context);
        $this->_url = $url;
    }

    public function execute()
    {
        //your code logic
        $productId = 'your product id';
        $storeCode = 'your store code';
        echo $this->_url->getUrl('catalog/product/view', ['id' => $productId, '_nosid' => true, '_query' => ['___store' => $storeCode]]);
    }

}

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.