Magento-在自定义页面模板上使用$ this-> getPriceHtml [英] Magento - using $this->getPriceHtml on custom page template

查看:99
本文介绍了Magento-在自定义页面模板上使用$ this-> getPriceHtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动条,显示了当前正在销售的产品的集合,可以使用以下内容来调用它:

I have a scroller showing a collection of products currently on sale, which I call using the following:

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('visibility', $visibility)
    ->setPageSize(4) // Only return 4 products
    ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
    ->addAttributeToFilter('special_to_date', array('or'=> array(
           0 => array('date' => true, 'from' => $todayDate),
           1 => array('is' => new Zend_Db_Expr('null')))
           ), 'left')
    ->addAttributeToSort('special_from_date', 'desc');
$_productCollection->load();

然后我运行一个foreach以获得单个产品:

I then run a foreach to get the individual products:

foreach ($_productCollection as $_product)

一切正常,除了价格,我通常会用

Everything works fine, except for the price, which I would usually call using

$this->getPriceHtml($_product, true)

但是,这给了我空白.如果我执行var_dump,则可以看到原始价格和特惠价格都可用,那为什么不能正常工作呢?我在首页模板上使用了与我的首页模板完全相同的代码,并通过首页CMS对其进行了调用,并且价格显示得很好(标出了正常价格并显示了特价).

However this is giving me a blank. If I do a var_dump I can see that both the original price and the special price are both available, so why isn't this working? I use exactly the same code on my homepage template, which I call through the homepage CMS, and the price is shown fine (with the regular price crossed out and special price shown).

使用 $ _ product-> getFinalPrice()可以很好地工作,但只能给我最终的特殊"价格,而不会显示原始价格.

Using $_product->getFinalPrice() works fine, but only gives me the final "special" price and doesn't show the original price.

我可能会在xml布局中丢失一些需要使用 getPriceHtml 显示价格的东西吗?

Am I maybe missing something in my xml layout that's needed to show the prices using getPriceHtml?

推荐答案

问题是getPriceHtml()函数是在Mage_Catalog_Block_Product块中定义的,而不是在标准Mage_Core_Block_Template中定义的.您需要确保您的代码块扩展了Product代码块,或者可以通过以下方式在布局中实现该目的:

The issue is that getPriceHtml() function is defined in the Mage_Catalog_Block_Product block, rather than the standard Mage_Core_Block_Template. You need to ensure that your block extends the Product block, or you can achieve that in your layout by something like:

<block type="catalog/product" name="blockname" template="path/to/template.phtml">

我还没有测试过,但是应该可以.

I haven't tested that, but it should work.

这篇关于Magento-在自定义页面模板上使用$ this-&gt; getPriceHtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆