Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

Changing the price in quote while adding product to cart: magento

I want to change the product price while add that product to cart.

How its possible let me know...

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The way to do it is add an observer which looks for this event 'sales_quote_add_item':

<events>
    <sales_quote_add_item>
        <observers>
            <priceupdate_observer>
                <type>singleton</type>
                <class>mymodule/observer</class>
                <method>updatePrice</method>
            </priceupdate_observer>
        </observers>
    </sales_quote_add_item>
</events>

The observer should have a method which does something like this:

public function updatePrice($observer) {
    $event = $observer->getEvent();
    $quote_item = $event->getQuoteItem();
    $new_price = <insert logic>
    $quote_item->setOriginalCustomPrice($new_price);
    $quote_item->save();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...