Get Default Country code from the current website Magento 2.

Get Default Country Value from the Current Website Using Programmatic way in Magento 2.

You can get the value of default country from the admin panel,
1. Stores -> Configuration -> General -> General
2. Country Options Tab -> Default Country.
Check the Selected Country value for the current website by set Store view as website scope. Continue reading “Get Default Country code from the current website Magento 2.”

Retrieve Store data by code programmatically Magento 2.

You can retrieve the store details by store code using Magento 2.

You required only store code to fetch data of the store. If store code is not valid throws the error,

The store that was requested wasn’t found. Verify the store and try again2.

Continue reading “Retrieve Store data by code programmatically Magento 2.”

Retrieve list of all stores programmatically in Magento 2.

Get list of all the stores in a system Programmatically Magento 2.

Store contains the information regarding, store_id, code, website_id, group_id, name, sort_order and is_active.

You can see all the list from the database table name, store

Interface Provides the functionality:
Magento\Store\Api\StoreRepositoryInterface

<?php
namespace Jesadiya\AllStore\Model;

use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\StoreRepositoryInterface;

class StoreList
{
    /**
     * @var StoreRepositoryInterface
     */
    private $storeRepository;

    public function __construct(
        StoreRepositoryInterface $storeRepository
    ) {
        $this->storeRepository = $storeRepository;
    }

    /**
     * Get Store list
     *
     * @return StoreInterface[]
     */
    public function getAllStoreList(): array
    {
        $storeList = $this->storeRepository->getList();

        return $storeList;
    }
}

Fetch all the store using iterate over a loop from the method,

$stores = $this->getAllStoreList();
foreach ($stores as $store) {
    echo $store->getStoreId(); // store id
    echo $store->getCode(); // store code
    echo $store->getName(); // name
    echo $store->getIsActive(); // is active?
    echo $store->getGroupId(); // group id
    echo $store->getSortOrder(); // Sort Order
}

Output: Array of all the store list in the system.