我们可以使用价格类型属性在magento中添加多个特殊价格吗? [英] Can we add more than one special price in magento using price type attribute?

查看:114
本文介绍了我们可以使用价格类型属性在magento中添加多个特殊价格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有定义了价格值的产品,如果我不提供该产品的特殊价格,我想使用某些属性显示除价格和特殊价格以外的其他价格.

I have product having price value defined, if I do not provide special price for that product, I want to display another price other than price and special price using some attribute.

并且当用户将产品添加到购物车时,该新价格应应用于该产品.

And when user adds the product to cart that time this new price should be applied to product.

如果可以的话,这在magento中可行吗?

Is this possible in magento if yes, how can I implement this?

更新:

update:

<强> config.xml中

<?xml version="1.0"?>
<config>
    <modules>
        <New_Price>
            <version>1.0.0</version>
        </New_Price>
    </modules>
   <global>
      <models>
            <price>
                <class>New_Price_Model</class>
            </price>            
        </models>     
        <events>
              <checkout_cart_product_add_after>
                    <observers>
                         <price>
                            <type>singleton</type>
                            <class>New_Price_Model_Observer</class>
                            <method>priceTocart</method>
                         </price>
                    </observers>
            </checkout_cart_product_add_after>
        </events>       
   </global>            
</config>

\ app \ code \ local \ Sigma \ New \ Model \ Observer.php

\app\code\local\Sigma\New\Model\Observer.php

Observer.php

class New_Price_Model_Observer extends Mage_Core_Model_Abstract
{
    public function priceTocart($observer)
    {
            Mage::log("hello",null,"pricelog.txt");             
            $quoteItem = $observer->getData();
            foreach($quoteItem as $cartItem)
            {                       
                echo $cartItem->getId()."<br>";
                echo $cartItem->getSpecialPrice()."<br>";
                echo $cartItem->getFinalPrice()."<br>";

                echo $cartItem->getRegularPrice()."<br>";

                echo $cartItem['regularprice']."<br>"; //This is my attribute values.I want to apply this value instead of final price.
            }           

    }
}   
?>

或者是否可以更改特殊价格的计算方式.如果是,我需要覆盖哪个文件.

Or Is it possible to change the way how special price is calculated. If yes which file I need to override.

推荐答案

可以相对简单地完成.首先,您需要扩展产品视图块并添加一个功能,以检查是否需要在产品页面上显示自定义价格.或者,创建一个辅助函数,您可以将产品对象传递给该辅助函数.然后,您可以在view.phtml模板中使用此功能,以便根据需要显示相应的自定义价格.

It can be done relatively simply. Firstly you need to extend the product view block and add a function to check if you need to show the custom price on the product page. Alternatively create a helper function that you can pass the product object into. You can then use this function in the view.phtml template to display the custom price accordingly however you please.

如果要显示正常价格(即替换价格),则需要修改price.phtml文件以进行检查,并将自定义属性显示为price(price.phtml是一个复杂的文件,但请查看特价是怎么做的.)

If you want it show where the normal price is (i.e. replace it) you need to modify your price.phtml file to do the check and show the custom attribute as the price (price.phtml is a complex file but look at how special price is done in it).

要更改添加到购物篮中的价格,您只需为checkout_cart_product_add_after事件创建一个事件观察器.您可以在此处访问报价项目,并且可以执行检查(即是否存在特价),并使用

To change the price on add to basket you simply create an event observer for the checkout_cart_product_add_after event. You have access to the quote item here and you can perform your checks (i.e. if special price is there or not) and set a custom price for a quote item using

$product = Mage::getModel('catalog/product')->load( $cartItem->getProductId() );    
$cartItem->setOriginalCustomPrice($product->getRegularprice());

这篇关于我们可以使用价格类型属性在magento中添加多个特殊价格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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