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"?>


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);
        $result = $client->catalogProductUpdate($session, $product_id, array(
                        'price' => $newPrice,
        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.

  • you want to update your price only in cart? – Gopal Patel Jan 27 '17 at 8:26
  • I want to update price on both cart and catalog. – Sachin Nagpal Jan 27 '17 at 8:34
  • means each time your customer place order you will fetch price from api and save price in cart and catalog. is your price is changing frequently? @sachin – Gopal Patel Jan 27 '17 at 8:57
  • Metal prices getting change every minute, so I want the order to be place with latest price. I am also running cron job to update catalog price in every 3 hours. – Sachin Nagpal Jan 27 '17 at 9:08
  • There may be some conflict if customers take longer time to complete payment – Gopal Patel Jan 27 '17 at 9:14

You can use sales_order_place_before Event

resides in app/code/core/Mage/Sales/Model/Order.php place() Function

$order = $observer->getEvent()->getOrder();
$quote = $order->getQuote();
if($quoteid) {
    foreach($quote->getAllItems() as $item){
        $item->setCustomPrice(<YOUR PRICE>);
        $item->setOriginalCustomPrice(<YOUR PRICE>);
| improve this answer | |
  • I tired the above solution and changed my code as you mentioned above, but its only updating the catelog price. Its not updating the cart price. – Sachin Nagpal Jan 27 '17 at 13:17
  • Have you set the price of quote item also? – Gopal Patel Jan 27 '17 at 13:20
  • @SachinNagpal find updated answer – Gopal Patel Jan 27 '17 at 13:42

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.