3

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?

3
  • Can you please upload your options file which you added in listing.xml? Commented Feb 25, 2020 at 6:15
  • currently, it showing using default feature ... no custom code written Commented Feb 25, 2020 at 6:16
  • Let me know if you have any confusion in answer. Commented Feb 25, 2020 at 6:47

2 Answers 2

2

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.

7
  • From where we need to call this code ?? I have to override vendor/magento/module-catalog/view/adminhtml/ui_component/product_listing.xml right ? Commented Feb 25, 2020 at 6:49
  • Yes. If you want to display in product grid. Then, need to override. Commented Feb 25, 2020 at 6:52
  • ok trying same. Commented Feb 25, 2020 at 6:53
  • @RohanHapani check my screen shot
    – Msquare
    Commented Feb 25, 2020 at 7:12
  • 1
    Yes it working perfectly Commented Feb 25, 2020 at 8:45
1

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.

4
  • i think u not understand my question Commented Feb 25, 2020 at 7:27
  • @Msquare is it your answer of question? or your separate question? Commented Feb 25, 2020 at 7:29
  • the answer is not related to my question its... answer if different question Commented Feb 25, 2020 at 8:47
  • @RohanHapani it' implementation of Question
    – Msquare
    Commented Feb 25, 2020 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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