如何在magento 2的UiComponent中获取目录产品

问题描述

我想在自定义UiComponent中获取目录产品。我试图通过现有的collectionfactory来获取Productdata,但是未获取数据。我正在使用的DataProvider是 Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection ,而CollectionFactory是 Magento \ Catalog \ Ui \ DataProvider \ Product \ Grid \ Collection 。这是我的di.xml

<virtualType name="AllexistproductGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Magento\Catalog\Model\ResourceModel\Product\Collection</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="allproductexist_listing_data_source" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Grid\Collection</item>
            </argument>
        </arguments>
    </type> 
    <type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">catalog_category_product</argument>           
            <argument name="resourceModel" xsi:type="string">Magento\Catalog\Model\ResourceModel\Product</argument>
        </arguments>
    </type>

如您所见,我认为我使用了错误的DataProvider和CollectionFactory。我不明白我必须使用哪个DataProvider和CollectionFactory来获取现有的目录产品。请帮忙。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)