1

I have an extra custom field on cart page. If any user inputs something in that field and updates the cart than I need to add extra 4 Pounds to the cart having label as "Extra Price".

I am using

<checkout_cart_save_after>
    <observers>
        <module_cart_update>
                <type>singleton</type>
                <class>webroot/observer</class>
                <method>logopriceMethod</method>
        </module_cart_update>
    </observers>
</checkout_cart_save_after>

Following is my current code :

public function logopriceMethod(Varien_Event_Observer $observer){
    $invoice = $observer->getEvent()->getInvoice();
    $order = $invoice->getOrder();
    $order->setExtraFeeAmountInvoiced($order->getExtraFeeAmountInvoiced() + 4);
    $order->setBaseExtraFeeAmountInvoiced($order->getExtraFeeAmountInvoiced() + 4);
}

But the above code gives me following error :

Fatal error: Call to a member function getOrder() on null in /var/www/clients/.../Model/Observer.php on line 52

I am using THIS module but it adds custom price as soon as a product is added to cart. What I am trying is to modify the code so as to add extra price on cart update (If there is any value in custom field on cart page).

1

Error is coming because invoice is null . Why its null ? For this you need to check the file where this event is being dispatched. This event is dispatched in class Mage_Checkout_Model_Cart on line 464 You will see this code

Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));

No invoice object has been passed as param and invoice is created after order has been placed , you can not get order or invoice until order is placed.
basically what you are looking for is adding a custom fee to your order
give a try to this link http://excellencemagentoblog.com/blog/2012/01/27/magento-add-fee-discount-order-total/
basic summary of the article is that you will have to create column for your custom fees in quote table and order table and you will have to set data in your quote's table column and at the time of placing order you will have to add few lines of code which will copy your custom fee to order table.
Give a try to article , this will gonna help you for sure.

  • i have tried this and it is not working in magento 1.9 also i have another module HERE but this is adding extra fee as soon as a product is added to the cart. What I need is to add price on cart update. – Wasiq Shahrukh Sep 29 '17 at 9:26

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.