0

This question already has an answer here:

with this code im getting http://url.com i want to get https://url.com using object manager. i'm using magento 2.0.4

 echo $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); echo '<br>';

marked as duplicate by Murtuza Zabuawala, Manoj Deswal, Priyank, Dhiren Vasoya, Prince Patel Feb 21 '18 at 5:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

I am daam sure below code will work

$store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB,true);

Why?? just check declaration in below class

/vendor/magento/framework/Url/ScopeInterface.php

and check 2nd param

0

Try using the below code:

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager            
) {
    $this->_storeManager = $storeManager;
}

echo $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true);

You can check more about the function getBaseUrl in Magento\Store\Model\Store Store Model class.

0

Try below,

 $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB,true);

Plese Note yoo need to add secure url in Store-> Configuration -> Web -> Base URLs (Secure)

Please check screenshot enter image description here

  • no didn't get from it, in Store-> Configuration -> Web -> Base URLs (Secure) i added: url.com in this field 'Secure Base URL' , next field 'Secure Base Link URL' i added: {{secure_base_url}} is this ok? – Ganesh Godshelwar Feb 15 '18 at 5:45
  • in Secure Base URL you need to define like (url.com) – Nilesh Gosai Feb 15 '18 at 5:57
0

For reference :vendor/magento/module-store/Test/Unit/Model/Service/StoreConfigManagerTest.php

/**
         * @var \Magento\Store\Model\Service\StoreConfigManager
         */
        protected $model;


    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\ResourceModel\Store\CollectionFactory
     */
    protected $storeCollectionFactoryMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Data\StoreConfigFactory
     */
    protected $storeConfigFactoryMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfigMock;

    protected function setUp()
    {
        $this->storeConfigFactoryMock = $this->getMockBuilder(\Magento\Store\Model\Data\StoreConfigFactory::class)
            ->disableOriginalConstructor()
            ->setMethods(['create'])
            ->getMock();
        $this->storeCollectionFactoryMock = $this->getMockBuilder(
            \Magento\Store\Model\ResourceModel\Store\CollectionFactory::class
        )->disableOriginalConstructor()
            ->setMethods(['create'])
            ->getMock();
        $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);

        $this->model = new \Magento\Store\Model\Service\StoreConfigManager(
            $this->storeCollectionFactoryMock,
            $this->scopeConfigMock,
            $this->storeConfigFactoryMock
        );
    }

AND GET BY THIS:

$code = 'default';
    $result = $this->model->getStoreConfigs([$code]);
    $result[0]->getSecureBaseUrl();

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