Can we add more than one special price in magento using price type attribute?

て烟熏妆下的殇ゞ 提交于 2019-12-08 06:45:23

问题


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.

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

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.


回答1:


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.

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).

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());



回答2:


You can only add one Special Price. If u want to do this with another Attribute, so you have to rewrite the price Index.

But you can create "catalog product rules" and as reference use the sku of the product.



来源:https://stackoverflow.com/questions/20949796/can-we-add-more-than-one-special-price-in-magento-using-price-type-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!