0

I have a couple store views that represent other languages, and I'm trying to get product attributes consisting of my site language. How do we retrieve product attributes from the admin store (store id 0)? I think I understand that we can switch between stores within a product, but the values retrieved are not from the admin store. My admin store product name is "A bunch of bananas."

$productId = $observer->getProduct()->getId();
$theProduct = $this->_productRepository->getById($productId);
$theProduct->setStoreId(0); //Set the admin store id
$value = $theProduct->getData('name');

$value is returned as "Un racimo de plátanos", which is not from my admin store.

I've tried the method outlined in this ticket as well.

getAttributeText() use default value regardless what store view the user is on

1

If you take a look at \Magento\Catalog\Model\ProductRepository, and it's method getById():

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

You'll notice that third parameter defines storeId. So, you can use something like:

$this->_productRepository->getById($productId, false, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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