Question

In my custom module, I am trying to add store filter in orderRepository using searchCriteriaBuilder but it is throwing an error like below.

1 exception(s): Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/CE/2.3.0/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296

Below is my code :

$searchCriteria = $this->searchCriteriaBuilder
    ->addFilter(
        'status', $orderStatus, 'eq'
    )->addFilter(
    'created_at', $date->format('Y-m-d 00:00:00'), 'gteq'
    )->addFilter(
        'created_at', $date->format('Y-m-d 23:59:59'), 'lteq'
    )->addFilter('store_id', $this->followUpEmailHelper->getStore(), 'eq')->create();

    $orderCollection = $this->orderRepository->getList($searchCriteria);

    print_r($orderCollection->getSelect()->__toString());die;

What is wrong in the above code and how to apply store filter in the collection using searchCriteriaBuilder


Update :

Marius answer is correct for my current issue is resolved but I want to how to get scope store id. because when i pass store id to this filter then it is always returned store 2.

Any help would be appreciated! Thanks!

Was it helpful?

Solution

Replace

->addFilter('store_id', $this->followUpEmailHelper->getStore(), 'eq')

with

->addFilter('store_id', $this->followUpEmailHelper->getStore()->getId(), 'eq')

OTHER TIPS

If you want to pass multiple storeId to Filter You can use in for multi-store select.

So your code looks like below :

$searchCriteria = $this->searchCriteriaBuilder
                        ->addFilter(
                            'status', $orderStatus, 'eq'
                        )->addFilter(
                            'created_at', $date->format('Y-m-d 00:00:00'), 'gteq'
                        )->addFilter(
                            'created_at', $date->format('Y-m-d 23:59:59'), 'lteq'
                        )->addFilter('store_id', $storeIds, 'in')->create();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top