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.

  • Can you please upload your file code? – Rohan Hapani Dec 11 '18 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 – Rutvee Sojitra Dec 11 '18 at 8:46
  • Please check my answer and let me know if not working. (use store code if require) – Rohan Hapani Dec 11 '18 at 9:16
  • it's working in this controller but not working in \Magento\ImportExport\Controller\Adminhtml\Import\Start – Rutvee Sojitra Dec 11 '18 at 9:18
  • okay. Let me check. – Rohan Hapani Dec 11 '18 at 9:22
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, privacy policy and cookie policy

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