0

I'm trying to get some data that matches the id in the URL. I have a param in admin URL like below.

seller/items/index/id/9/

I'm using the admin UI component which is working fine.

My model code below.

protected function _initSelect() {        

$urlInterface = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\UrlInterface');
$getId = explode("/",$urlInterface->getCurrentUrl());        
$idString = $getId[9];
//$id = (int)$idString;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
$request = $objectManager->get('Magento\Framework\App\Request\Http');  
$id = $param = $request->getParam('id');
$this->addFilterToMap('increment_id', 'main_table.increment_id');
$this->addFilterToMap('status', 'main_table.status');

$this->getSelect();
parent::_initSelect();
$this->addFieldToFilter('main_table.seller_id', ['eq' => $id]);

return $this;        
}

I'm getting the Id in this model page when I var_dump. But it is not filtering. It is showing zero records, but if I give static id in the condition it works. Seems like the model starts loading before the page rendered.

1 Answer 1

0

$this->addFilterToMap('increment_id', 'main_table.increment_id');

$this->addFilterToMap('status', 'main_table.status');

$this->addFieldToFilter('main_table.seller_id', ['eq' => $id]);

Make sure the id you get is correct

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.