Magento - 使用替代的“price.phtml” (除了现有的)
我正在寻找一种方法,在一个特定位置使用备用 template/catalog/product/price.phml
,并继续在所有其他位置使用现有的 Price.phtml 文件。
为了进一步解释,我需要显示正常价格,然后在其正下方显示另一个特价 - 但仅在产品页面上(对于显示的主要产品)。这个特价不是可以按照目录价格规则计算的价格,所以我自己写了一个模块来做计算。因此,在我显示价格的任何地方,我都想使用常规的 template/catalog/product/price.phtml
文件显示...但对于产品页面(主要产品 - 不是相关产品) 、追加销售等)我想使用自己的自定义 template/catalog/product/price-custom.phtml
模板文件。有人可以帮忙吗?
通常我只是查看布局 xml 文件(例如catalog.xml)来查找这些类型的内容,但price.phtml 有点特殊 - 它并不那么简单。对于我的一生,我无法弄清楚是否有一种简单的方法可以在正在查看的页面上有条件地交换它。我知道我可以更新price.phtml以始终打印出这个额外的价格,然后使用css来隐藏各处的价格,但如果可能的话我宁愿不这样做。
(另外你可能想知道我只有简单的产品。)
I am looking for a way to have an alternate template/catalog/product/price.phml
used in one specific location, and to continue using the existing price.phtml file in all other locations.
To explain further, I need to display the regular price, and then another special price right below it - but only on the product page (for the main product being displayed). This special price is not a price that can be calculated by the catalog price rules, so I wrote my own module to do the calculation. So, everywhere that I am displaying prices I want to display with the regular ol' template/catalog/product/price.phtml
file... but for the product page (the main product - not the related, upsells, etc) I want to use my own custom template/catalog/product/price-custom.phtml
template file. Can anybody help?
Normally I just look in the layout xml files (for example catalog.xml) to find these types of things, but price.phtml is kinda special - it isn't that simple. And for the life of me I can't figure out if there is an easy way to swap it out conditionally on the page being viewed. I am aware that I can just update price.phtml to always print out this extra price, and then use css to hide the price everywhere, but I would rather not do that if possible.
(Also you may want to know that I only have simple products.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可以在布局 XML 文件中完成:
This can be done in a layout XML file:
创建
local.xml
文件,放在app/frontend/default/YOURTEMPLATE/layout
中local.xml
文件中,添加:创建
catalog/product/price.phtml
的副本并将其放入YOURTEMPLATE/templates/product/product_price_page.phtml
这将覆盖 price.phtml 在模板中,并将其替换为
product_price_page.phtml
Create a
local.xml
file, put it inapp/frontend/default/YOURTEMPLATE/layout
In the
local.xml
file, add:Create a copy of
catalog/product/price.phtml
and put it inYOURTEMPLATE/templates/product/product_price_page.phtml
This will override the price.phtml in the template, and replace it with
product_price_page.phtml
或者在你的 php 块中。
请参阅此处的示例:
Mage_Catalog_Block_Product_Abstract
Or in your php block.
See example here :
Mage_Catalog_Block_Product_Abstract
我最近有类似的要求,产品页面的不同价格模板是首选解决方案。
价格块似乎是 Magento 中的一个特殊情况(至少在 RWD 主题中),它在 catalog.xml 中定义为
句柄:如果您查看一些核心布局文件如何设置价格模板,您会发现这样的示例(来自bundle.xml):
它们调用名为
addPriceBlockType
您可以在 Mage_Catalog_Block_Product_Abstract 中找到基于此并经过一些实验,我发现以下解决方案对我有用:
I had a similar requirement recently, where a different price template for the product page was the preferred solution.
The price block appears to be something of a special case in Magento (in the RWD theme at least), it's defined in catalog.xml as simply a block type and name within the
<default/>
handle:If you look around at how some core layout files set the price template, you'll find examples like this (from bundle.xml):
They call a method called
addPriceBlockType
which you can find in Mage_Catalog_Block_Product_AbstractBased on this and after a little experimentation, I found the following solution worked for me:
实现它的正确方法:
...
The proper way to achieve it :
...