Skip to main content
added 99 characters in body
Source Link
Haijerome
  • 2.2k
  • 18
  • 21

InYou dont need a source class as its a customer address attribute, check your customer address type source fileattribute settings, make sure you have set Yes for Add to Column Options and Use in Filter Options

Zest\Integration\Model\Customer\Attribute\Source\AddressType.phpIn your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

You dont need a source class as its a customer address attribute, check your customer address attribute settings, make sure you have set Yes for Add to Column Options and Use in Filter Options

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

added 10 characters in body
Source Link
Haijerome
  • 2.2k
  • 18
  • 21

To get your value in the admin grid, the code should be

in your ui_component xml file

<column name="addresstype" component="Magento_Ui/js/grid/columns/select" sortOrder="95">
            <settings>
                <addField>true</addField>
                <options class="Zest\Integration\Model\Customer\AddressType\Source"class="Zest\Integration\Model\Customer\Attribute\Source\AddressType"/>
                <filter>select</filter>
                <sortable>false</sortable>
                <dataType>select</dataType>
                <label translate="true">Address Type</label>
            </settings>
        </column>

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

<?php

namespace Zest\Integration\Model\Customer\Attribute\Source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
use Magento\Framework\Data\OptionSourceInterface;

/**
 *  returns customer's address type source
 *
 */
class AddressType extends AbstractSource implements SourceInterface, OptionSourceInterface
{
    
   
    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
        return [ 0 => __('No'), 1 => __('Yes')];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option text by option value
     *
     * @param string $optionId
     * @return string
     */
    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }

}

To get your option values in the grid for select type columns , you need an attribute source class like the one above

To modify the value in the grid you need a renderer class like the one that you've added in the question.

To get your value in the admin grid, the code should be

in your ui_component xml file

<column name="addresstype" component="Magento_Ui/js/grid/columns/select" sortOrder="95">
            <settings>
                <addField>true</addField>
                <options class="Zest\Integration\Model\Customer\AddressType\Source"/>
                <filter>select</filter>
                <sortable>false</sortable>
                <dataType>select</dataType>
                <label translate="true">Address Type</label>
            </settings>
        </column>

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

<?php

namespace Zest\Integration\Model\Customer\Attribute\Source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
use Magento\Framework\Data\OptionSourceInterface;

/**
 *  returns customer's address type source
 *
 */
class AddressType extends AbstractSource implements SourceInterface, OptionSourceInterface
{
    
   
    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
        return [ 0 => __('No'), 1 => __('Yes')];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option text by option value
     *
     * @param string $optionId
     * @return string
     */
    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }

}

To get your option values in the grid for select type columns , you need an attribute source class like the one above

To modify the value in the grid you need a renderer class like the one that you've added in the question.

To get your value in the admin grid, the code should be

in your ui_component xml file

<column name="addresstype" component="Magento_Ui/js/grid/columns/select" sortOrder="95">
            <settings>
                <addField>true</addField>
                <options class="Zest\Integration\Model\Customer\Attribute\Source\AddressType"/>
                <filter>select</filter>
                <sortable>false</sortable>
                <dataType>select</dataType>
                <label translate="true">Address Type</label>
            </settings>
        </column>

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

<?php

namespace Zest\Integration\Model\Customer\Attribute\Source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
use Magento\Framework\Data\OptionSourceInterface;

/**
 *  returns customer's address type source
 *
 */
class AddressType extends AbstractSource implements SourceInterface, OptionSourceInterface
{
    
   
    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
        return [ 0 => __('No'), 1 => __('Yes')];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option text by option value
     *
     * @param string $optionId
     * @return string
     */
    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }

}

To get your option values in the grid for select type columns , you need an attribute source class like the one above

To modify the value in the grid you need a renderer class like the one that you've added in the question.

Source Link
Haijerome
  • 2.2k
  • 18
  • 21

To get your value in the admin grid, the code should be

in your ui_component xml file

<column name="addresstype" component="Magento_Ui/js/grid/columns/select" sortOrder="95">
            <settings>
                <addField>true</addField>
                <options class="Zest\Integration\Model\Customer\AddressType\Source"/>
                <filter>select</filter>
                <sortable>false</sortable>
                <dataType>select</dataType>
                <label translate="true">Address Type</label>
            </settings>
        </column>

In your customer address type source file

Zest\Integration\Model\Customer\Attribute\Source\AddressType.php

<?php

namespace Zest\Integration\Model\Customer\Attribute\Source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
use Magento\Framework\Data\OptionSourceInterface;

/**
 *  returns customer's address type source
 *
 */
class AddressType extends AbstractSource implements SourceInterface, OptionSourceInterface
{
    
   
    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
        return [ 0 => __('No'), 1 => __('Yes')];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option text by option value
     *
     * @param string $optionId
     * @return string
     */
    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }

}

To get your option values in the grid for select type columns , you need an attribute source class like the one above

To modify the value in the grid you need a renderer class like the one that you've added in the question.