3
2009
Add to Cart with custom attributes & values
I want to display the custom price on the Shopping Cart page. By default if you add to cart the product it will take the price & will show that price on the cart page.
The data on the cart page is coming from the table ‘sales_flat_quote_item’. This table is having lot many fields. Some of them are product_id, name, description, qty, price. Those are the fields which basically reflects on the cart page.
My task was to display the custom image, custom price, custom description in the row of a product on the cart page.
So first of all we need to insert those values in the DB, while adding the product to the cart.
The phase of adding the product to cart is bit complicated to understand.
These are list of some functions involved in Add to cart phase.
app/code/core/Mage/Checkout/controllers/CartController.php: addAction()
app/code/core/Mage/Checkout/Model/Cart.php: addProduct($product, $info)
app/code/core/Mage/Sales/Model/Quote.php: addProduct(Mage_Catalog_Model_Product $product, $request=null)
In the above function, you can set the custom values for the product.
Find the for loop:
foreach ($cartCandidates as $candidate) { … }
Inside that custom fields can be set.
foreach ($cartCandidates as $candidate) {
$item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());
...
...
...
$item->setCustomPrice('custom value goes here');
$item->setCustomImage('custom value goes here');
...
...
}
I want the custom image as well. So I have added the one more field in the table ‘sales_flat_quote_item’.
Getting those custom values on the cart page is very easy. Go to template/checkout/cart/item/default.phtml.
The below lines can get those values.
echo $_item->getCustomImage();
The price on the cart page will replaced automatically by custom_price value if that has been set.

An article by
How can i add custom options of bundle product’s item in cart ??
Hi Rakesh
can you please discuss all the changes you made for assigning custom price for product.
thanks
John
Friend this helped me a lot. But still i am struggling with an issue. I need to put a custom field (select/text) in the product page (for all products) and the customer can choose the or enter the option. I need the value of this field displayed in cart page and also stored in quote items. Hope you will help me
Thanks in advance.
Very useful article, I was trying to set custom price and for this written a long code in cart model. It helped a lot.
very useful articles – keep them coming!