Skip to content

Undefined index on product listing modifier

I created a product custom attribute

    $eavSetup->addAttribute(
        Product::ENTITY,
        'is_subscription_product',
        [
            'is_visible_in_grid' => true,
            'is_html_allowed_on_front' => false,
            'visible_on_front' => false,
            'visible' => true,
            'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_STORE,
            'label' => __('Subscription'),
            'source' => MagentoCatalogModelProductAttributeSourceBoolean::class,
            'backend' => MagentoCatalogModelProductAttributeBackendBoolean::class,
            'type' => 'int',
            'is_used_in_grid' => true,
            'required' => false,
            'input' => 'boolean',
            'is_filterable_in_grid' => true,
            'sort_order' => 10,
            'group' => 'Subscription',
        ]
    );
}

It’s properly created everywhere…now I want to add a modifier on that grid for this attribute.

To do so i’m creating

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="product_columns">
        <column name="is_subscription_product" class="VendorSubscriptionModelProductAttributeRendererIsSubscription">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

And in the renderer class i’m doing something like that

public function prepareDataSource(array $dataSource)
{
    if (isset($dataSource['data']['items'])) {
        foreach ($dataSource['data']['items'] as &$item) {
            if($this->getData('name') == 'is_subscription_product') {
                if($item['is_subscription_product']){

But then I’m hitting the error

Notice: Undefined index: is_subscription_product

I don’t get why the data is not in the $item object….cause if I remove the modifier the data is rendered in grid…so it should be there…what am I missing ?