문제

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?

도움이 되었습니까?

해결책

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'];
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top