Pergunta

I want to go through all options of attributes configured for filtering and output the label of the Admin Store View. I only managed to get the Default Store View (store_id 1) label with the following code:

$coll = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection::class);
$coll->addIsFilterableFilter();
$layeredNavAttributes = $coll->load()->getItems();

foreach ($layeredNavAttributes AS $attr) {
    $options = $attr->getSource()->getAllOptions();
    foreach ($options AS $option) {
      echo $option['label'];
    }
}

How can I get the labels of the Admin Store View (store_id 0) instead?

Foi útil?

Solução

After some more trying, I came to the answer myself. Just call the setStoreId() method on each attribute. So the code to get the Admin labels looks like this:

$coll = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection::class);
$coll->addIsFilterableFilter();
$layeredNavAttributes = $coll->load()->getItems();

foreach ($layeredNavAttributes AS $attr) {
    $attr->setStoreId(0);
    $options = $attr->getSource()->getAllOptions();
    foreach ($options AS $option) {
      echo $option['label'];
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top