Magento:在产品页面上两次显示价格 [英] Magento: Display price twice on product pages

查看:102
本文介绍了Magento:在产品页面上两次显示价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在产品页面上生成价格的代码:

This is the code that generates the price on product pages:

<?php  echo $this->getPriceHtml($_product) ?>

* app/design/frontend/default/CUSTOM_TEMPLATE/template/catalog/product/view.phtml *

我有一个带有一些自定义选项的简单产品.当客户选择选项之一时,价格会上涨.一切正常,直到这里.

I have a simple product with a few custom options. When the customer selects one of the option, the price increases. All works fine until here.

我的问题是如何在同一页面上两次显示价格(出于设计目的需要该价格)?

My question is how can i display the price twice on the same page (need this for deign purposes)?

我试图将以上代码复制并粘贴到同一页面上的两个位置,但是问题是,选择了产品选项后,第二个价格将不会更新.只有一次价格更新,第二次不会.关于如何使它起作用的任何想法?

I tried to copy and paste the above code in two locations on the same page, but the problem is that the second price will not update when the product options are selected. Only one price updates, the second won't. Any ideas on how can i make it work?

推荐答案

页面上最有可能使用JavaScript来计算新价格,或使用AJAX来获取新价格.因此,价格输出如下:

There is most likely a JavaScript on the page that either calculates the new price, or fetches it with AJAX. So the price outputted with:

<?php echo $this->getPriceHtml($_product) ?>

将被新的覆盖.要解决此问题,您需要找到Javascript并找到执行此操作的位置.您还应该检查getPriceHtml调用周围包含哪些HTML元素.我猜模板可能有这样的东西:

Will get overwritten by the new one. Solving this requires that you find the Javascript and locate where it does this. You should also check what HTML element surrounds the getPriceHtml-call. I guess the template might have something like this:

<p class="totalProductPrice"><?php echo $this->getPriceHtml($_product) ?></p>

如果您用可识别的类名或ID的元素包围第二个价格输出的输出,则应该能够修改Javascript以将新计算的价格以及该原始价格输出到该元素.

If you surround the output of your second price output with an element with identifiable classname or ID, you should be able to modify the Javascript to output the newly calculated price to that element as well as the original one.

检查完我自己的代码库后,我认为您要查找的文件位于/js/varien/Product.js.在函数reloadPrice: function()内,检查第481行:

After checking my own codebase, I think that the file you are looking for is located at /js/varien/Product.js. Inside the function reloadPrice: function(), check line 481 for this:

    if($('product-price-'+this.config.productId)){
        $('product-price-'+this.config.productId).innerHTML = price;
    }

并修改脚本以更新您的第二个价格元素.

And modify the script to also update your second price element.

这篇关于Magento:在产品页面上两次显示价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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