2

In my custom created module I'm trying to get the grid page in admin working.

I have everything routed, and I'm able to get to the correct page (so i see all of the magento elements, but my grid has an error). When the page is loaded I get the error:

Class Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection does not exist

My collection code is as followed:

namespace Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid;

use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Wavelabs\StoreLocator\Model\ResourceModel\Store\Collection as StoreCollection;

use \Magento\Framework\Data\Collection\EntityFactoryInterface;
use \Psr\Log\LoggerInterface;
use \Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use \Magento\Framework\Event\ManagerInterface;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\EntityManager\MetadataPool;
use \Magento\Framework\Model\ResourceModel\Db\AbstractDb;

/**
 * Class Collection
 * Collection for displaying grid of sales documents
 */
class Collection extends StoreCollection implements SearchResultInterface
{
/**
 * @var AggregationInterface
 */
protected $aggregations;

/**
 * @param EntityFactoryInterface $entityFactory
 * @param LoggerInterface $logger
 * @param FetchStrategyInterface $fetchStrategy
 * @param ManagerInterface $eventManager
 * @param StoreManagerInterface $storeManager
 * @param MetadataPool $metadataPool
 * @param mixed|null $mainTable
 * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
 * @param mixed $eventObject
 * @param mixed $resourceModel
 * @param string $model
 * @param null $connection
 * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
 *
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
 */
public function __construct(
    EntityFactoryInterface $entityFactory,
    LoggerInterface $logger,
    FetchStrategyInterface $fetchStrategy,
    ManagerInterface $eventManager,
    StoreManagerInterface $storeManager,
    EntityManager\MetadataPool $metadataPool,
    $mainTable,
    $eventPrefix,
    $eventObject,
    $resourceModel,
    $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
    $connection = null,
    AbstractDb $resource = null
) {
    parent::__construct(
        $entityFactory,
        $logger,
        $fetchStrategy,
        $eventManager,
        $storeManager,
        $metadataPool,
        $connection,
        $resource
    );
    $this->_eventPrefix = $eventPrefix;
    $this->_eventObject = $eventObject;
    $this->_init($model, $resourceModel);
    $this->setMainTable($mainTable);
}

/**
 * @return AggregationInterface
 */
public function getAggregations()
{
    return $this->aggregations;
}

/**
 * @param AggregationInterface $aggregations
 * @return $this
 */
public function setAggregations($aggregations)
{
    $this->aggregations = $aggregations;
}

/**
 * Get search criteria.
 *
 * @return \Magento\Framework\Api\SearchCriteriaInterface|null
 */
public function getSearchCriteria()
{
    return null;
}

/**
 * Set search criteria.
 *
 * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
{
    return $this;
}

/**
 * Get total count.
 *
 * @return int
 */
public function getTotalCount()
{
    return $this->getSize();
}

/**
 * Set total count.
 *
 * @param int $totalCount
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setTotalCount($totalCount)
{
    return $this;
}

/**
 * Set items list.
 *
 * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
 * @return $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function setItems(array $items = null)
{
    return $this;


  }
}

My di.xml is as followed:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="store_listing_data_source" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <type name="Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">wavelabs_storelocator_stores</argument>
            <argument name="eventPrefix" xsi:type="string">store_grid_collection</argument>
            <argument name="eventObject" xsi:type="string">store_grid_collection</argument>
            <argument name="resourceModel" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store</argument>
        </arguments>
    </type>
    <virtualType name="storeGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="storeGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Wavelabs\StoreLocator\Model\ResourceModel\Store\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">storeGirdFilterPool</argument>
        </arguments>
    </virtualType>
</config>

I'm not 100% sure which files I need to include here. So if anyone need more information, please ask me :D

ResourceModel/Store.php

namespace Wavelabs\StoreLocator\Model\ResourceModel;


use \Magento\Framework\Model\ResourceModel\Db\AbstractDb;

class Store extends AbstractDb

{
    protected function _construct()

    {
        $this->_init('wavelabs_storelocator_store', 'store_id');

    }

}

ResourceModel/Store/Collection.php

namespace Wavelabs\StoreLocator\Model\ResourceModel\Store;


use Wavelabs\StoreLocator\Model\ResourceModel\AbstractCollection;

class Collection extends AbstractCollection
{
    /**
     * @var string
     */
    protected $_idFieldName = 'store_id';

    /**
     * Load data for preview flag
     *
     * @var bool
     */
    protected $_previewFlag;

    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('Wavelabs\StoreLocator\Model\Store', 'Wavelabs\StoreLocator\Model\ResourceModel\HelloWorld');
    }


    public function setFirstStoreFlag($flag = false)
    {
        $this->_previewFlag = $flag;
        return $this;
    }

    /**
     * Add filter by store
     *
     * @param int|array|\Magento\Store\Model\Store $store
     * @param bool $withAdmin
     * @return $this
     */
    public function addStoreFilter($store, $withAdmin = true)
    {

        return $this;
    }

    /**
     * Perform operations after collection load
     *
     * @return $this
     */
    protected function _afterLoad()
    {

        return parent::_afterLoad();
    }

    /**
     * Perform operations before rendering filters
     *
     * @return void
     */
    protected function _renderFiltersBefore()
    {
        return parent::_renderFiltersBefore();
    }
}

Model/Store.php

namespace Wavelabs\StoreLocator\Model;

use \Magento\Framework\Model\AbstractModel;


class Store extends AbstractModel
{
    protected function _construct()
    {
        $this->_init('Wavelabs\StoreLocator\Model\ResourceModel\Store');
    }
}
  • have you shared full code of that Collection.php? – kunj Aug 22 '18 at 13:28
  • Yes this is my full code of Grid/Collections.php – David Kooijman Aug 22 '18 at 13:29
  • I think you forgot to close Collection class }. – kunj Aug 22 '18 at 13:32
  • Please check there is no Typo in folder name also check case sensitivity. – Rutvee Sojitra Aug 22 '18 at 13:32
  • 1
    You must check path of your grid collection, which should be app/code/Wavelabs/StoreLocator/Model/ResourceModel/Store/Grid/ – Kumar M Aug 22 '18 at 14:27
0

Please update your di.xml code with below code:

    <?xml version="1.0"?>
  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <virtualType name="Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
   <arguments>
        <argument name="mainTable" xsi:type="string">wavelabs_storelocator_stores</argument>
        <argument name="eventPrefix" xsi:type="string">store_grid_collection</argument>
        <argument name="eventObject" xsi:type="string">store_grid_collection</argument>
        <argument name="resourceModel" xsi:type="string">Wavelabs\Store\Model\ResourceModel\Store</argument>
    </arguments>
</virtualType>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="store_listing_data_source" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection</item>
        </argument>
    </arguments>
</type>
 <virtualType name="storeGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
    <arguments>
        <argument name="appliers" xsi:type="array">
            <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
            <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
        </argument>
    </arguments>
</virtualType>
<virtualType name="storeGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
    <arguments>
        <argument name="collection" xsi:type="object" shared="false">Wavelabs\StoreLocator\Model\ResourceModel\Store\Collection</argument>
        <argument name="filterPool" xsi:type="object" shared="false">storeGirdFilterPool</argument>
    </arguments>
</virtualType>

after changing code fire two command:

rm -rf generated/* and cache:clean and check

| improve this answer | |
  • 1
    Thank you for the reply. I now get Class Wavelabs\StoreLocator\Model\ResourceModel\Store does not exist – David Kooijman Aug 22 '18 at 13:43
  • @DavidKooijman, confirm that file and class exist – kunj Aug 22 '18 at 13:46
  • 1
    Can you please add your Wavelabs\StoreLocator\Model\ResourceModel\Store code in question – Rutvee Sojitra Aug 22 '18 at 13:46
  • I added the code. The class is there in my folder structure – David Kooijman Aug 22 '18 at 13:49
  • 1
    @DavidKooijman please edir one more line in di.xml <argument name="resourceModel" xsi:type="string">Wavelabs\Store\Model\ResourceModel\Store</argument> to <argument name="resourceModel" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store</argument> here your Namespace is wrong and check after it – Rutvee Sojitra Aug 22 '18 at 13:50
0

Always good to check path letter by letter. What I had:

app/code/Wavelabs/StoreLocator/Model/ResouceModel/Store/Grid

What I need:

app/code/Wavelabs/StoreLocator/Model/ResourceModel/Store/Grid/

Feeling a bit like an idiot right now! But thanks everyone

| improve this answer | |
0

In your di.xml, you have

<argument name="resourceModel" xsi:type="string">Wavelabs\Store\Model\ResourceModel\Store</argument>

But based on the info you've provided, it should be

<argument name="resourceModel" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store</argument>
| improve this answer | |
  • Thank you for the answer, this indeed helped solve the problem a little more. I answered my own question for what made it work fully again! – David Kooijman Aug 23 '18 at 7:56

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.