Magento 2 Get Store Specific Product Name and Description

Today we’ll talk about how we can get store specific products name and descriptions. Like for example, my shop has six store views: DE, AT, IT, ES, FR, and GB. And each store view uses the same set of the product with appropriately translated but I would for example want to view a product in a specific view like DE.

We can do that just by following the instructions below:

protected $productFactory;  
public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory) {      
 $this->productFactory = $productFactory;            
}

now you can use this like,

$product= $this->_productFactory->create()->setStoreId($storeId)->load($pid);

Where $storeIdis your store Id and
$pidis your product Id.

$productName=$product->getName();

Don’t forget to do

di:compile

by

php bin/magento setup:di:compile

and clearcache

php bin/magento c:f

Product Repository

protected $productRepository;
public function __construct(             \Magento\Catalog\Api\ProductRepositoryInterface $productRepository    )
{        
$this->productRepository = $productRepository;    
}

Now, you can use below

$product = $this->productRepository->getById($pid,false,$storeId);

$productName=$product->getName();

You can see It’s arguments invendor\magento\module-catalog\Api\ProductRepositoryInterface.phppublic function getById($productId, $editMode = false, $storeId = null, $forceReload =

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply