0
public function paymentEvent(Varien_Event_Observer $observer) {
    $this->log("Entramos al observer");
    $quote = $observer->getQuote();
    $store = Mage::app()->getStore($quote->getStoreId());
    $cartItems = $quote->getAllVisibleItems();

foreach($cartItems as $item) {
  $newPrice = $this->getNewPrice($item->getPrice()); // Function that calculate the newPrice (%)
  $item->setCustomPrice($newPrice);
  $item->setOriginalCustomPrice($newPrice);
  $item->getProduct()->setIsSuperMode(true);
  $item->save();

}
$this->log("Observer END");
return $this;

}

This function change the product prices depending the payment Method selected.

Observer Method Event: sales_quote_payment_import_data_before

But if for some reason the customer changes his payment method, the prices keeps at the same amount.

Example: first i choose Payment Method Y and works ok, but if for some reason i need to changa the payment method and i go back to step 4 and now i choose payment method Z, all the calculates are made with the payment method Y, i need again to go back to step 4 and choose again Payment Method Z and now it shows the prices ok.

Theres any form to flush the payment method choosen if the customer go back to step 4 or another one?

2
  • did you verify that, you get recent selection of payment methods when observer called? – Dhiren Vasoya Jan 3 '17 at 3:19
  • Yes i have a log file, there's shows that information, and looks everything ok. I don't know whats happening but if i change to another payment method i need to choose it twice. Because the firstone still haves the information of the firstime that i choosen the payment. – Waskalle Jan 3 '17 at 18:22
0

First, sales_quote_payment_import_data_before event fire when importData(array $data) is called.

So, you need to change when you have changing the payment gateway that times,need to ensure that $QuoteObject->getPayment()->importData($data) called.

Also after run $item->save();,you should called

$quote->collectTotals()->save();

for calculated total price and assign new price to quote

2
  • public function fetch(Mage_Sales_Model_Quote_Address $address) { // my code is here } I Change the observer for a Model Class which is executed after payment Method is selected. My log file shows all ok, ut I still need 2 times to choose the payment method to update the view – Waskalle Jan 3 '17 at 17:43
  • Do u know wich event was executed after paymentMethod is choosen? – Waskalle Jan 3 '17 at 23:39
0

I know this answer is late, but had the same question / problem using observer sales_quote_payment_import_data_before...

the code uses the old payment method.

To get the new chosen method, you can use:

Mage::app()->getFrontController()->getRequest()->getParams()

You'll get:

[payment] => Array
    (
        [method] => method_code_chosen
    )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.