Magento - 使用替代的“price.phtml” (除了现有的)

发布于 2024-10-13 04:28:09 字数 617 浏览 1 评论 0原文

我正在寻找一种方法,在一个特定位置使用备用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不甘平庸 2024-10-20 04:28:09

这可以在布局 XML 文件中完成:

<layout>
    <PRODUCT_TYPE_simple>
        <reference name="product.clone_prices">
            <action method="setTemplate">
                <template>catalog/product/price-custom.phtml</template>
            </action>
        </reference>
    </PRODUCT_TYPE_simple>
</layout>

This can be done in a layout XML file:

<layout>
    <PRODUCT_TYPE_simple>
        <reference name="product.clone_prices">
            <action method="setTemplate">
                <template>catalog/product/price-custom.phtml</template>
            </action>
        </reference>
    </PRODUCT_TYPE_simple>
</layout>
素年丶 2024-10-20 04:28:09

创建local.xml文件,放在app/frontend/default/YOURTEMPLATE/layout

local.xml文件中,添加:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <!-- Override price template on product view page -->               
    <PRODUCT_TYPE_simple>
        <reference name="product.info.simple">
            <action method="setTemplate">
                <template>catalog/product/price_product_page.phtml</template>
            </action>
        </reference>
    </PRODUCT_TYPE_simple>
    <!-- /Override price template on product view page -->              
</layout>

创建catalog/product/price.phtml 的副本并将其放入 YOURTEMPLATE/templates/product/product_price_page.phtml

这将覆盖 price.phtml 在模板中,并将其替换为 product_price_page.phtml

Create a local.xml file, put it in app/frontend/default/YOURTEMPLATE/layout

In the local.xml file, add:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <!-- Override price template on product view page -->               
    <PRODUCT_TYPE_simple>
        <reference name="product.info.simple">
            <action method="setTemplate">
                <template>catalog/product/price_product_page.phtml</template>
            </action>
        </reference>
    </PRODUCT_TYPE_simple>
    <!-- /Override price template on product view page -->              
</layout>

Create a copy of catalog/product/price.phtml and put it in YOURTEMPLATE/templates/product/product_price_page.phtml

This will override the price.phtml in the template, and replace it with product_price_page.phtml

无需解释 2024-10-20 04:28:09

或者在你的 php 块中。

请参阅此处的示例:

Mage_Catalog_Block_Product_Abstract

protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
protected $_tierPriceDefaultTemplate  = 'catalog/product/view/tierprices.phtml';

Or in your php block.

See example here :

Mage_Catalog_Block_Product_Abstract

protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
protected $_tierPriceDefaultTemplate  = 'catalog/product/view/tierprices.phtml';
遗失的美好 2024-10-20 04:28:09

我最近有类似的要求,产品页面的不同价格模板是首选解决方案。

价格块似乎是 Magento 中的一个特殊情况(至少在 RWD 主题中),它在 catalog.xml 中定义为 句柄:

<block type="catalog/product_price_template" name="catalog_product_price_template" />

如果您查看一些核心布局文件如何设置价格模板,您会发现这样的示例(来自bundle.xml):

<reference name="catalog_product_price_template">
    <action method="addPriceBlockType">
        <type>bundle</type>
        <block>bundle/catalog_product_price</block>
        <template>bundle/catalog/product/price.phtml</template>
    </action>
</reference>

它们调用名为 addPriceBlockType 您可以在 Mage_Catalog_Block_Product_Abstract 中找到

基于此并经过一些实验,我发现以下解决方案对我有用:

<catalog_product_view>
    <reference name="product.info">
        <action method="addPriceBlockType">
            <type>simple</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_product_page.phtml</template>
        </action>
        <action method="addPriceBlockType">
            <type>configurable</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_product_page.phtml</template>
        </action>
        <!-- Set for each product type as necessary e.g. bundled, virtual etc... -->
    </reference>
</catalog_product_view>

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:

<block type="catalog/product_price_template" name="catalog_product_price_template" />

If you look around at how some core layout files set the price template, you'll find examples like this (from bundle.xml):

<reference name="catalog_product_price_template">
    <action method="addPriceBlockType">
        <type>bundle</type>
        <block>bundle/catalog_product_price</block>
        <template>bundle/catalog/product/price.phtml</template>
    </action>
</reference>

They call a method called addPriceBlockType which you can find in Mage_Catalog_Block_Product_Abstract

Based on this and after a little experimentation, I found the following solution worked for me:

<catalog_product_view>
    <reference name="product.info">
        <action method="addPriceBlockType">
            <type>simple</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_product_page.phtml</template>
        </action>
        <action method="addPriceBlockType">
            <type>configurable</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_product_page.phtml</template>
        </action>
        <!-- Set for each product type as necessary e.g. bundled, virtual etc... -->
    </reference>
</catalog_product_view>
无名指的心愿 2024-10-20 04:28:09

实现它的正确方法:

<PRODUCT_TYPE_simple>
    <reference name="product.info.simple">
        <action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
    </reference>
</PRODUCT_TYPE_simple>

<PRODUCT_TYPE_configurable>
    <reference name="product.info.configurable">
        <action method="addPriceBlockType"><type>configurable</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
    </reference>
</PRODUCT_TYPE_configurable>

...

The proper way to achieve it :

<PRODUCT_TYPE_simple>
    <reference name="product.info.simple">
        <action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
    </reference>
</PRODUCT_TYPE_simple>

<PRODUCT_TYPE_configurable>
    <reference name="product.info.configurable">
        <action method="addPriceBlockType"><type>configurable</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
    </reference>
</PRODUCT_TYPE_configurable>

...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文