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];
}
1
  • can you print this code $this->getIndices() to see what data are you getting? also, share a screenshot
    – Mohit Rane
    Aug 19, 2019 at 11:01

2 Answers 2

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.

2
  • it show me a blank page not any result Aug 19, 2019 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 Aug 19, 2019 at 9:51
1

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] ?? [];
}
2
  • it show me a blank page now Aug 19, 2019 at 10:35
  • not show me a result after search in searchbar Aug 19, 2019 at 10:36

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.