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