3

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!

1

Replace

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

with

->addFilter('store_id', $this->followUpEmailHelper->getStore()->getId(), 'eq')
  • What a silly mistake Thanks – Chirag Patel May 9 at 13:45
  • 1
    But it always returns store_id = 2 – Chirag Patel May 9 at 13:49
  • 1
    I cannot help you with that. I have no idea what followUpEmailHelper is and what it does. – Marius May 9 at 13:58
  • followUpEmailHelper is a my module helper file where i get store id. – Chirag Patel May 9 at 13:59
  • Your answer is correct to my question and my store issue is not relevant to this Thanks :) – Chirag Patel May 10 at 4:44
2

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();

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.