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>';
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>';
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
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.
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)
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();