I have 4 store view. In this store view i have products. Store view differ in the names of products. I want to fetch product only from one storeview. Now i can fetch product from main, first store view. How can i switch store view to fetch product from second store view where product have different name.
1 Answer
As per my understanding, i think you have to get store specific product name and other product data. you can achieve these things using below code.
Load product factory in construct method
protected $_productFactory;
public function __construct(
\Magento\Catalog\Model\ProductFactory $_productFactory
) {
$this->_productFactory = $_productFactory;
}
Now you can use like below.
$product= $this->_productFactory->create()->setStoreId($storeId)->load($pid);
$productName=$product->getName();
Where $storeId is your store Id and $pid is your product Id.
You can also use product repository (\Magento\Catalog\Api\ProductRepositoryInterface $productRepository)
instead of product factory (\Magento\Catalog\Model\ProductFactory)
I hope it helps!