1

I have a custom module that works with the default Magento quote factory. Here, I am fetching the quote data using the,

\Magento\Quote\Model\QuoteFactory $quoteFactory

and in my block I am getting the store name as

public function getStoreName() {
    return $this->_storeManager->getStore()->getName();
}

However, when there are multiple store views, the above code always displays the store as Default Store View. Is there anyway we can get the store name according to the quote object that was created?

Please can anyone help?

1

You can fetch your store id from your quote object and after that from id you can fetch your store name from your store id.

Please see my code.

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();    
$storeManager = $objectManager->create("\Magento\Store\Model\StoreManagerInterface");
$storeId = $quote->getStoreId();
    $stores = $storeManager->getStores(true, false);
    foreach($stores as $store){
    if($store->getId() === $storeId){
        $storeName = $store->getName();
    }
   }
echo $storeName;
  • You shouldn't use the object manager, see: devdocs.magento.com/guides/v2.2/extension-dev-guide/… – steros Jul 20 '18 at 6:22
  • Yes, i can't use objectmanager but i just give the solution for it. And they can make instance of storemanager. – Dharmendra Jadav Jul 20 '18 at 6:23
  • @DharmendraJadav I tried your code with store manager instance and not object manager, but I am getting the storeId but the store name is empty. – manini Jul 20 '18 at 6:46
  • 1
    @manini Please try to print $store object and checked store name is available or not. echo '<pre>;print_r($store->getData());die; – Dharmendra Jadav Jul 20 '18 at 6:56
  • I changed the $store->getStoreName() to $store->getName() and it is working fine. Thanks a lot. – manini Jul 20 '18 at 7:05
1

You need to use the instance of \Magento\Framework\App\Config\ScopeConfigInterface in your block:

public function getStoreviewName()
{

 return $this->_scopeConfig->getValue(
        'general/store_information/name',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    );


}

and call in your template echo $this->getStoreviewName()

  • This is returning the same store name for all. There are some quotes that have been created using other store views as well. Is there anyway to determine the store view used for that quote? – manini Jul 20 '18 at 6:29

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.