#StackBounty: #eav #magento2.2.2 What is the right way to get both, the admin translation and the frontend value of a multiselect attri…

Bounty: 250

I am using the following code to fetch the admin option value as well as the frontend label from an ID list of vales of a multiselect.

    $attribute = $this->eavConfig->getAttribute('catalog_product', self::ATTRIBUTE_CODE);
    $adminAttribute = clone $attribute;
    $adminAttribute->setStoreId(0);

    $result = [];
    foreach(array_unique($allIds) as $id) {
        $description = $attribute->getSource()->getOptionText($id);
        $fileName = $adminAttribute->getSource()->getOptionText($id);
        $result[$fileName] = $description;
    }

In a block on the product list this seems to work, while it does not look clean for me. Anyways, on a product detail page it does not (I get for $fileName still the frontend value, not the admin value).

Is there a proper way to do this?

EDIT I was thinking about loading the product in Admin store, still I get the non-admin-store value:

$adminProduct = $this->_productRepository->getById($product->getId(), false, 0);
$adminProduct->getAttributeText(self::ATTRIBUTE_CODE);


Get this bounty!!!

Leave a Reply