2

I want to show the duplicate entries in Admin Grid. that grid is created by join there tables. If any duplicate entry from my custom table, Grid returns the error as below,

Item (Magento\Framework\View\Element\UiComponent\DataProvider\Document) with the same ID "1" already exists.

how to disable this duplicate entry check in grid/collection.php My Collection.php is below,

<?php


namespace Webkul\Pos\Model\ResourceModel\Delivery\Grid;
use Psr\Log\LoggerInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Search\AggregationInterface;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Webkul\Pos\Model\ResourceModel\Delivery\Collection as DeliveryCollection;

class Collection extends DeliveryCollection implements SearchResultInterface  {

    protected $_aggregations;
    protected $_objectManager;

    public function __construct(
        EntityFactoryInterface $entityFactory,
        LoggerInterface $logger,
        FetchStrategyInterface $fetchStrategy,
        ManagerInterface $eventManager,
        StoreManagerInterface $storeManager,
        ObjectManagerInterface $objectManager,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null,
        $model = "Magento\Framework\View\Element\UiComponent\DataProvider\Document"
    )  {
        $this->_objectManager = $objectManager;
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }



    public function getAggregations()  {
        return $this->_aggregations;
    }

    public function setAggregations($aggregations)  {
        $this->_aggregations = $aggregations;
    }

    public function getSearchCriteria()  {
        return null;
    }

    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)  {
        return $this;
    }

    public function getTotalCount()  {
        return $this->getSize();
    }

    public function setTotalCount($totalCount)  {
        return $this;
    }

    public function setItems(array $items = null)  {
        return $this;
    }

}

My model\ResourceModel\Delivery Collectio.php is below,

<?php
 namespace Webkul\Pos\Model\ResourceModel\Delivery;

use 
Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection  {

    protected $_idFieldName = "order_id";

    protected function _construct()  {
        $this->_init("Webkul\Pos\Model\Delivery", "Webkul\Pos\Model\ResourceModel\Delivery");


    }

    protected function _initSelect()
    {
      parent::_initSelect();
      $this->getSelect()->join(
            ['secondTable'=>$this->getTable('sales_order_address')],
            'main_table.order_id = secondTable.entity_id','*');
      $this->getSelect()->join(
            ['thirdTable'=>$this->getTable('sales_order_grid')],
            'main_table.order_id = thirdTable.entity_id', '*');

      }

    public function setDeliveryData($condition, $attributeData)  {
        return $this->getConnection()->update($this->getTable("pos_delivery"), $attributeData, $where = $condition);
    }

}

Anyone please help me.. Thanks in Advance

7
  • So you want show duplicate entries or want disable? Commented Oct 10, 2018 at 10:32
  • i want to show duplicate entries @RutveeSojitra
    – Ask Xah
    Commented Oct 10, 2018 at 10:36
  • If you want to show duplicate entry primary keywise it is not possible. because all mass action will perform on base of primary key Commented Oct 10, 2018 at 10:37
  • no im doing all mass actions in a separate auto gen id. I want to show the duplicate entry of another key order_id from my cutom table @RutveeSojitra
    – Ask Xah
    Commented Oct 10, 2018 at 10:38
  • Please add your Webkul\Pos\Model\ResourceModel\Delivery\Collection as DeliveryCollection code in question Commented Oct 10, 2018 at 10:39

1 Answer 1

3

Please change

protected $_idFieldName = "order_id";

with

protected $_idFieldName= "id"

Because your custom tables primary key is id not order_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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