搜索时显示产品价格

时间:2017-10-18 10:53:56

标签: php magento-1.9

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

这是显示产品特征的负责任功能

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,

        );
    }

}

2 个答案:

答案 0 :(得分:2)

只需添加此行即可 &#39;价格&#39; =&GT;建议数组中的$ _product-&gt; getPrice()

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

    );

答案 1 :(得分:2)

你可以使用

$_product->getFinalPrice()

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

相关问题