Question

Admin: When we add any product attribute(Type Drop-Down) in the filter on the product list at that time default store value is showing in filter drop-down options so I want to show admin label value instead of the default store value. See attached screenshot for more information enter image description here

enter image description here

I have check admin configuration but not found anything does anyone have idea how this is possible?

Était-ce utile?

La solution

You need to create custom file for add options in dropdown like below way :

<item name="options" xsi:type="object">Vendor\Module\Ui\Component\Listing\Column\Myoptions</item>

You need to add this line in your ui field of color. After that, Create Myoptions.php file and add this below code :

<?php

namespace Vendor\Module\Ui\Component\Listing\Column;

class Myoptions implements \Magento\Framework\Option\ArrayInterface
{
    public function __construct(
        \Magento\Eav\Model\Config $eavConfig
    ) {
        $this->eavConfig = $eavConfig;
    }

    public function toOptionArray()
    {
        $attribute = $this->eavConfig->getAttribute('catalog_product', 'activity')->setStoreId(0);
        $allOptions = $attribute->getSource()->getAllOptions();
        $attrOptionsArray = [];
        foreach ($allOptions as $attrKey => $attrValue) {
            $attrOptionsArray[$attrKey]['label'] = $attrValue['label'];
            $attrOptionsArray[$attrKey]['value'] = $attrValue['value'];
        }
        return $attrOptionsArray;
    }
}

Replace your attribute code instead of activity.

Clean cache and check it.

Autres conseils

I create same as attribute

enter image description here

but i check admin name not show in filter it is filter using some diffrent value show here

enter image description here

And i get Array like this for using below code

$_code = 'product_demo';
        $_attribute = $this->_objectManager->get("Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory")->create();
        $attribute = $_attribute->loadByCode(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, $_code);

        $options = $attribute->getSource()->getAllOptions(true);
        print_r($options);
        $attrOptionsArray = [];
        foreach ($options as $attrKey => $attrValue) {
            $attrOptionsArray[$attrKey]['label'] = $attrValue['label'];
            $attrOptionsArray[$attrKey]['value'] = $attrValue['value'];
        }
        print_r($attrOptionsArray);

show array here

Array
(
    [0] => Array
        (
            [label] =>  
            [value] => 
        )

    [1] => Array
        (
            [value] => 5640
            [label] => view-1
        )

    [2] => Array
        (
            [value] => 5641
            [label] => view-2
        )

    [3] => Array
        (
            [value] => 5642
            [label] => view-3
        )

    [4] => Array
        (
            [value] => 5643
            [label] => view-4
        )

)
Array
(
    [0] => Array
        (
            [label] =>  
            [value] => 
        )

    [1] => Array
        (
            [label] => view-1
            [value] => 5640
        )

    [2] => Array
        (
            [label] => view-2
            [value] => 5641
        )

    [3] => Array
        (
            [label] => view-3
            [value] => 5642
        )

    [4] => Array
        (
            [label] => view-4
            [value] => 5643
        )

)

Admin value not shown only default value is show.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top