4

I have created an admin page with a specialised ui component, which renders my custom table "galleries", which has several field "gallery_id", "colour", "background colour" etc.

When loading the table, magento correctly returns the number of rows of my data, but none of the actual values are returned because it is looking for the values in "getCustomAttributes()", not in the table which I have created.

So I get the following error: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\magento\vendor\magento\framework\View\Element\UiComponent\DataProvider\DataProvider.php on line 252

The line throwing the error is

foreach ($item->getCustomAttributes() as $attribute) 

because, while $item exists, and $searchResult->getTotalCount() returns the correct total, my items have no custom attributes.

I would like to know, if possible, how I can "link" my custom table "GALLERIES" to the custom attributes tables, which I believe are catalog_product_entity_varchar, catalog_product_entity_int etc, in order to display my values.

This is the code block in which the error is thrown, in magento\framework\View\Element\UiComponent\DataProvider\DataProvider.php

/**
 * @param SearchResultInterface $searchResult
 * @return array
 */
protected function searchResultToOutput(SearchResultInterface $searchResult)
{
    $arrItems = [];

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $itemData = [];
        /* THROWS ERROR foreach ($item->getCustomAttributes() as $attribute) {
            $itemData[$attribute->getAttributeCode()] = $attribute->getValue();
        } */
        $arrItems['items'][] = $itemData;
    }

    $arrItems['totalRecords'] = $searchResult->getTotalCount();
    return $arrItems;

}         
0

I had the same issue, your Gallery model class should extend AbstractExtensibleModel instead of AbstractModel class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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