0

I have tried to load collection in custom grid Based on current product data

<?php
$redirectUrl = $this->helper->getCurrentProduct();
             $objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
            $request = $objectManager->get('Magento\Framework\App\Request\Http');  
            $param = $request->getParams();
            $productId =  $param['current_id'];
             $product = $this->helper->getLoadProduct($productId);
             $sku = $product->getSku();
             $TestData = $product->getTestData();
             $TestDatasarr = explode("|", $TestData);
             $TestDatavalues = "'" . implode("', '", $TestDatasarr) . "'";
            $this->getSelect()->orwhere("main_table.testdatas IN($TestDatavalues)");

In the above code i got $TestDatavalues like 'test','test1','test2' when I pass the values manually in getslect in like $this->getSelect()->orwhere("main_table.testdatas IN('test','test1','test2')");

It shows the collection data but when I pass the variable it shows empty data $this->getSelect()->orwhere("main_table.testdatas IN($TestDatavalues)"); when i print it shows the empty

Can anyone help on this.

1
  • Can anyone help on this
    – kanidhaya
    Commented Jun 12, 2020 at 4:03

1 Answer 1

0

You should use the code below:

$this->getSelect()->orwhere("main_table.testdatas IN(?)", $TestDatavalues);
4
  • I have tried again it shows empty data
    – kanidhaya
    Commented Jun 12, 2020 at 5:11
  • If i pass the values in manually it shows data but i am also get the value from $TestDatavalues while pass in variable it shows empty
    – kanidhaya
    Commented Jun 12, 2020 at 5:12
  • if i print query $test = $this->getSelect()->where("main_table.testdatas IN($TestDatavalues)")->__toString(); var_dump($test); It shows the query of the output perfect when run the same in phpmyadmin but in grid it does not shows the data
    – kanidhaya
    Commented Jun 12, 2020 at 16:41
  • Can anyone help me on this tried lot of methods
    – kanidhaya
    Commented Jun 12, 2020 at 16:41

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.