So today, we want to introduce you to the best solution to manage the product price and currency easily at each store view:
Writing is a part of my life and I’m living for it.
What Is Magento 2 Store Base URL?
Run the following code:
Each Magento website has a base URL assigned to the storefront and another one assigned to the admin.
Table of Contents
- Base URL: http://www.yourdomain.com/magento/
- Secure Base URL: https://www.yourdomain.com/magento/
- URL with IP address: http://###.###.###.###/magento/ or https://###.###.###.###/magento/
How To Get Magento 2 Store Base URL?
The standard base URL begins with HTTP, and the secure base URL begins with HTTPS.
- Using the Magento core method
- Using object manager
Using the Magento core method
We hope this blog is helpful and good luck to you!
We hope this blog is helpful and good luck to you!
It also enables you to choose the base currency for each store view and supports checking out with the base currency so your customers can purchase with their preferred currency.
There are two methods to get Magento 2 Store Base URL:
Magento uses variables to define internal links in relation to the base URL, thus you can move the whole store from one location to another without updating the link.
Let’s get started!
<?php
namespace [Vendor][Module]Helper; use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;
use MagentoStoreModelStoreManagerInterface; class Data extends AbstractHelper
{
protected $storeManager; public function __construct(
Context $context,
StoreManagerInterface $storeManager
)
{
$this->storeManager = $storeManager;
parent::__construct($context);
} public function getStoreManagerData()
{
$storeUrl = $this->storeManager->getStore()->getBaseUrl(); // get Store Url without index.php
$storeUrl = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB); // get Link Url of store
$storeLinkUrl = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK); // get media Base Url
$storeMediaUrl = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA); // get Static content Url
$storeStaticUrl = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC);
}
}
Using object manager
In this article, we have shown 2 simple methods to get your Magento 2 store base URL.
- Set up different prices, special prices and tier prices for a product per store view
- Set up base currency per store view
- Customers checkout with the base currency of their store view conveniently
- Set up various special prices for a product per store view
Conclusion
BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bringing high-quality products and services to optimize your business effectively. Furthermore, we offer FREE Installation – FREE 1-year Support and FREE Lifetime Update for every Magento extension.
This extension allows you to set any price type for a product, including regular price, special price and tier price. And these prices can be different among your store views for the same product.
In this article, we will show you how to get your Magento 2 store base URL using very simple code.
This module allows you to set up Minimum Order Amount, Shipping Cost and Custom Options Price for each store view, too.