0
  1. My shop has 6 store views: DE, AT, IT, ES, FR, GB
  2. Each store view uses the same set of product (but appriopriate translated)

Now, I would like to get product name from IT only for example. How do I do it?

Thanks!

2
  • In what context? Get IT product name where?
    – Ryan Hoerr
    Commented Jun 5, 2017 at 14:36
  • It's happening in Controller execute() function Commented Jun 5, 2017 at 14:43

1 Answer 1

6
protected $_productFactory;  

in construct add this

  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 $storeId is your store Id and $pid is your product Id.

$productName=$product->getName();

Don't forget to do di:compile by

php bin/magento setup:di:compile and clear cache

php bin/magento c:f

EDIT

For productRepository

protected $productRepository;

in construct add this

 public function __construct(     
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,

    ) {
        $this->productRepository = $productRepository;
    }

Now, you can use this

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

You can see It's arguments in

vendor\magento\module-catalog\Api\ProductRepositoryInterface.php

public function getById($productId, $editMode = false, $storeId = null, $forceReload = false);

2
  • I'm using Product Repository and would prefer to stick with it. Any other solutions? Commented Jun 5, 2017 at 15:02
  • See my edit .. @PeteJaworski
    – Keyur Shah
    Commented Jun 5, 2017 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.