2

In this function-

 public function getResults()
{
    $results = [];
    foreach ($this->getLoadedProductCollection() as $product) {
        $data['img'] = $this->encodeMediaUrl(
            $this->getImage($product, 'amasty_xsearch_page_list')- 
>toHtml()
        );
        $data['url'] = $product->getProductUrl();
        $data['name'] = $this->getName($product);
        $data['description'] = $this->getDescription($product);
        $data['sku'] = $this->getSku($product);
        $data['price'] = $this->getProductPrice($product);
        $data['is_salable'] = $product->isSaleable();
        $data['product_data'] = [
            'entity_id' => (string)$product->getId(),
            'request_path' => (string)$product->getRequestPath()
            ];
        $data['reviews'] = $this->getReviewsSummaryHtml($product, 
   ReviewRendererInterface::SHORT_VIEW);
        $results[$product->getId()] = $data;
    }

    $this->setNumResults($this->getLoadedProductCollection()- 
>getSize());
    return $results;
        }

I added this line-

$data['sku'] = $this->getSku($product);

I then created this function-

public function getSku(\Magento\Catalog\Model\Product $product)
{
    return $this->getResults()->get($sku);
}

On the page I am trying to display it on I have this code-

 <?= $product['sku'] ?>

The extension pulls the name and description so I tried to just copy what was done for those attributes but it doesn't seem to work.

1
  • your getSku function should recieved a $sku variable public function getSku($sku) { return $this->getResults()->get($sku); }
    – fmsthird
    Commented Apr 18, 2019 at 21:14

1 Answer 1

2

Seems as it infinity call stack, can you edit your added line to

$data['sku'] = $product->getSku();

or edit your function to

public function getSku(\Magento\Catalog\Model\Product $product)
{
   return $product->getSku();
}
3
  • I changed the function and that worked great, but I don't understand why. Could you explain a little if you get a chance? If not I really appreciate the help. Commented Apr 18, 2019 at 21:59
  • @TylerJensen inner function getResult you call getSku then inside getSku call getResult, it is a infinity stack trace. Commented Apr 19, 2019 at 4:35
  • That makes sense thanks you. Commented Apr 19, 2019 at 13:31

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.