:::: MENU ::::

Magento 2 Get Store Specific Product Name and Description

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 =

Author: Qaisar Satti
Category: Magento 2
Last Modified: September 29, 2020


So, what do you think ?