Magento2 – How to load Quote by Quote id

By Using Object Manager you can inject the instace of \Magento\Quote\Model\QuoteFactory The other and recommended way, you can load the quote id by injecting the instance of \Magento\Quote\Model\QuoteFactory To use it you can write: $q = $this->quoteFactory->create()->load($quoteId);
Posted in Guides, Magento Questions, Quote & Orders | Tagged , , , , , , | 2 Comments

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.
Posted in Guides, Magento Questions | Leave a comment

Magento2 – How to get Current Url

To get url of the current page, the code below works everywhere: $objectManagerInstance = \Magento\Framework\App\ObjectManager::getInstance(); $url = objectManagerInstance -> get(‘Magento\Framework\UrlInterface’); echo $url -> getCurrentUrl(); From a .phtml template you can also do it shorter by calling the \Magento\Framework\View\Element\AbstractBlock::getUrl(); Without using objectManager you can use inside your class here Initialize your object : private $_urlInterface Now …
Posted in Guides | 4 Comments

Magento2 – How to get Directory of a Module

Here is the code how to load your module directory: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $directoryReader = $objectManager->create(‘\Magento\Framework\Module\Dir\Reader’); $moduleDirectory = $directoryReader->getModuleDir(”, ‘Knowthemage_Hello’); echo “Directory : “.$moduleDirectory;
Posted in Guides, Modules | Leave a comment

Magento2 – How to get Current locale Programmatically

Inject Resolver Dependency and get locale in your phtml And in your phtml:
Posted in Countries & Addresses, Guides | 3 Comments

Magento2 – How to Get Country Name Using Country Code

Create Instance to Object Manager then inject dependency to perform your query: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); Now load your country by the following code: $country = $objectManager->create(‘\Magento\Directory\Model\Country’)->load(‘AE’)->getName(); While AE is the country code. The output of above code will be: United Arab Emirates
Posted in Countries & Addresses, Guides | Leave a comment

Magento2 How to Get Country Code Collection

To get country list data, you need to create instance of Country collection model `Magento\Directory\Model\ResourceModel\Country\CollectionFactory`. Once instance is created, you can load it by current store.
Posted in Countries & Addresses, Guides | Tagged , , | Leave a comment