Magento2 – How to get store information

Magento2 – How to get store information
()
By default store manager loads current store information. You can get store information by `store_id` parameter.You must create an instance of \Magento\Store\Model\StoreManagerInterface class to get store information.
<?php
...

    private $storeManager;

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

	/**
	 * Returns Current Store id.
	 *
	 * @return int
	 */
	public function getStoreId()
	{
		return $this->getStore()->getId();
	}

	/**
	 * Returns Current Store Code.
	 *
	 * @return string
	 */
	public function getStoreCode()
	{
		return $this->getStore()->getCode();
	}

	/**
	 * Returns Current Store Name.
	 *
	 * @return string
	 */
	public function getStoreName()
	{
		return $this->getStore()->getName();
	}

	/**
	 * Returns Store Data Model Interface.
	 *
	 * @return \Magento\Store\Api\Data\StoreInterface
	 */
	public function getStore()
	{
		return $this->storeManager->getStore();
	}

	/**
	 * Loads Store information by store id parameter.
	 *
	 * @param int $storeId
	 * @return \Magento\Store\Api\Data\StoreInterface
	 */
	public function getStoreById($storeId)
	{
		return $this->storeManager->getStore($storeId);
	}

...

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

1 Comment

  • awesome

Leave a Reply

Your email address will not be published. Required fields are marked *