In Magento we can check cart as a Summary of product added by us for buying.
We can see cart Items containing Product Name , Image , Price , Quantity and Sub Total.
At the end we can see total too may be with or without shipping.
Now as a Developer We need to customize Cart item. Lets say example we want to update cart Item price ,so it will affect with cart item sub total and with the final total too.
So lets say we will add Some amount in the product price.
Current Item price for Product A is 5 and B is 10,
Lets add 10 more to both the products so now it is A is 15 and B is 20 ,
So with their respective quantity its total will affected and the final cart amount will be changed.
Question is how to do , its very simple.
Magento Provide Observer and its a great help for developer like us.
So we will create Observer with event as “checkout_cart_product_add_after”
Please check below code for detail view :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Get Product added to cart and update price by observer checkout_cart_product_add_after </title> </head> <body> <!--Get Product added to cart and update price by observer checkout_cart_product_add_after --> <?php // Get the quote item $item = $observer->getQuoteItem(); // Ensure we have the parent item, if it has one $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); // Load the custom price $price = "10"; // Set the custom price $item->setCustomPrice($price); $item->setOriginalCustomPrice($price); // Enable super mode on the product. $item->getProduct()->setIsSuperMode(true); ?>