:::: MENU ::::
Posts tagged with: store

Magento 2 Current Store Date Time

Today we talk about how in Magento 2 Current Store Date Time. Following this example you can get store date and time in block, helper, controller or model too. So let start with our example.
You need to inject in your class constructor an instance of Magento\Framework\Stdlib\DateTime\DateTime.

protected $date;
public function __construct(
   
    \Magento\Framework\Stdlib\DateTime\DateTime $date,

) {
   
    $this->date = $date;

}

Then, you can use in your class this:

$date = $this->date->gmtDate();
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


Magento 2 store information

Today we talk about how to get Magento 2 store information. In Store information we get the current store id , store code , store website id ,store name and also the available currencies in current store.So let start with example.

<?php
namespace QaisarSatti\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{    
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        array $data = []
    )
    {            
        parent::__construct($context, $data);
    }
   public function getStoreInfromation()
   {
        return $this->_storeManager->getStore();
   }
}

In phtml file get the information

$storeInformation = $block->getStoreInfromation();

$storeInformation->getStoreId();  //get store id
$storeInformation->getCode();  // get store code
$storeInformation->getWebsiteId(); // get store website id
$storeInformation->getName();  //get store name

//To get available currencies in store you check

foreach($storeInformation->getAvailableCurrencyCodes() as $codes):
  echo $codes;
endforeach;
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018