搜索时显示产品价格

Display product price when searching

我购买了一个显示弹出窗口的搜索模块,想在其中添加我搜索的产品的价格,我找到了我应该进行更改的文件,但是我应该添加什么来显示产品价格

这是负责显示商品特性的函数

protected function _prepareProducts()
{
    $isEnabledImage = (bool) Mage::getStoreConfig(self::ENABLE_IMAGE_CONFIG);
    $imageHeight    = (int) Mage::getStoreConfig(self::IMAGE_HEIGHT_CONFIG);
    $imageWidth     = (int) Mage::getStoreConfig(self::IMAGE_WIDTH_CONFIG);

    $isEnabledDescription = (bool) Mage::getStoreConfig(self::ENABLE_DESCRIPTION_CONFIG);
    $lengthDescription    = (int) Mage::getStoreConfig(self::DESCRIPTION_LENGTH_CONFIG);

    $collection = $this->_getAlternativeProductCollection();

    // $this->_prepareQueryPopularity($collection->getSize());

    $toolbar = $this->getToolbarBlock();

    $toolbar->setCollection($collection);

    $size = (int) Mage::getStoreConfig(self::RESULT_SIZE_CONFIG);
    $collection->setPageSize($size);
    // $collection->getSelect()->limit($size);
    $sortOrder = Mage::getStoreConfig(self::SORT_ORDER_PRODUCT);

    if (0 < count($collection)) {
        $this->_suggestions[$sortOrder][] = array('html' =>
            '<p class="headercategorysearch">' . $this->__("") . '</p>'
        );
    }
    if ($isEnabledImage) {
        $helper = Mage::helper('catalog/image');
    }

    foreach ($collection as $_row) {

        $_product = Mage::getModel('catalog/product')
            ->setStoreId($this->getStoreId())
            ->load($_row->getId());

        $_image = $_srcset = $_description = '';

        if ($isEnabledImage) {
            $_image  = (string) $helper->init($_product, 'thumbnail')->resize($imageWidth, $imageHeight);
            $_srcset = (string) $helper->init($_product, 'thumbnail')->resize($imageWidth * 2, $imageHeight * 2);
            $_srcset .= ' 2x';
        }
        if ($isEnabledDescription) {
            $_description = strip_tags($this->_trim(
                $_product->getShortDescription(),
                $lengthDescription
            ));
        }

        // $store = Mage::app()->getStore();
        // $path = Mage::getResourceModel('core/url_rewrite')
        //     ->getRequestPathByIdPath('product/' . $_product->getId(), $store);
        // // $url = $store->getBaseUrl($store::URL_TYPE_WEB) . $path;
        // $url = rtrim(Mage::getUrl($path, array('_store' => $store->getStoreId())), '/');
        $url = $_product->getProductUrl();
        $this->_suggestions[$sortOrder][] = array(
            'name'        => $_product->getName(),
            'url'         => $url,
            'image'       => $_image,
            'srcset'      => $_srcset,
            'description' => $_description,

        );
    }

}

只需添加这一行 'price' => 建议数组中的 $_product->getPrice()

      $this->_suggestions[$sortOrder][] = array(
        'name'        => $_product->getName(),
        'price'       => $_product->getPrice(),
        'url'         => $url,
        'image'       => $_image,
        'srcset'      => $_srcset,
        'description' => $_description,

    );

你可以使用

$_product->getFinalPrice()

在这个 _suggestions 属性 中,但我想还有一个模板或一些 js 负责所有这些的输出。