I am having an API that give me price of metals and I want to use that price just before placing an order and re calculate the cart price before order has been placed.
In order to do that I created an observer. Here is the code for config file:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<CustomPriceUpdate_Checkout>
<version>0.0.1</version>
</CustomPriceUpdate_Checkout>
</modules>
<global>
<models>
<myCustomPriceUpdate_Checkout>
<class>CustomPriceUpdate_Checkout_Model</class>
</myCustomPriceUpdate_Checkout>
</models>
<events>
<sales_order_place_before>
<observers>
<modify_product_price>
<type>singleton</type>
<class>myCustomPriceUpdate_Checkout/observer</class>
<method>update_price</method>
</modify_product_price>
</observers>
</sales_order_place_before>
</events>
</global>
</config>
Observer.php:
<?php
class CustomPriceUpdate_Checkout_Model_Observer{
public function update_price($observer){
$client = new SoapClient('http://domain.com/index.php/api/v2_soap/?wsdl');
$session = $client->login('username', 'key');
$quote = $observer->getQuote();
foreach ($quote->getAllItems() as $item) {
$product = $item->getProduct();//if you need it
$product_id = $product->getId();
$price = $product->getPrice();
$discountprice = 23;
$newPrice = ($price)+($discountprice);
$product->setPrice($newPrice);
$result = $client->catalogProductUpdate($session, $product_id, array(
'price' => $newPrice,
),'brisbanebullion');
Mage::log($product_id, null, "order.log", true);
}
}
}
I am using catalogProductUpdate API to update the price. The above code is only updating the price of Product, but its not updating the cart prices.
If I use the trigger "checkout_cart_save_before", then its changing price in both cart and catalog.
Can anyone please suggest me, which trigger I should use to update cart price just when user click place order button on checkout page.