1

Exception #0 (Exception): Notice: Undefined offset: 0 in /var/www/clients/client0/web2/web/app/code/Mirasvit/Search/Block/Result.php

 * @return IndexInterface
 */
public function getFirstMatchedIndex()
{
    foreach ($this->getIndices() as $index) {
        if (($index->getData('store_id') == false
            || $index->getData('store_id') == $this->getCurrentStore()->getId())
        ) {
            return $index;
        }
    }

    return $this->getIndices()[0];
}
  • can you print this code $this->getIndices() to see what data are you getting? also, share a screenshot – Mohit Rane Aug 19 at 11:01
  • +1 for answer acceptance :) – Shoaib Munir Aug 19 at 12:40
2

use this code instead

* @return IndexInterface
 */
public function getFirstMatchedIndex()
{
    foreach ($this->getIndices() as $index) {
        if (($index->getData('store_id') == false
            || $index->getData('store_id') == $this->getCurrentStore()->getId())
        ) {
            return $index;
        }
    }

    if(count($this->getIndices()) > 0){
        return $this->getIndices()[0];
    }
    return array();
}

This should work.

  • it show me a blank page not any result – Junaid Ashfaq Aug 19 at 9:49
  • After using above code your error should resolve. The blank page is causing from the code where getFirstMatchedIndex() function calling, you need to debug that – Shoaib Munir Aug 19 at 9:51
0

It's because you're calling an index that does not exist in the array.

public function getFirstMatchedIndex()
{
    // Return empty array if no indices.
    if (!$this->getIndices()) {
       return [];
    }

    foreach ($this->getIndices() as $index) {
        if ($index->getData('store_id') === false) {
           return $index;
        } elseif ($index->getData('store_id') === $this->getCurrentStore()->getId()) {
           return $index;
        }
    }

    /*
     * Return indice at index 0 or empty array if index 
     * does not exist.
     */
    return $this->getIndices()[0] ?? [];
}
  • it show me a blank page now – Junaid Ashfaq Aug 19 at 10:35
  • not show me a result after search in searchbar – Junaid Ashfaq Aug 19 at 10:36

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.