Are you looking for the solution i.e. customer can provide their inputs or comments along with the products they are going to order. To make it easier, one way is to allow them enter the comments for each individual item they order.
On the other hand, admin should be able to view the comment on the order page.
Adding a custom comment box for each item in the cart is actually very easy. First lets add the textarea field for each item.
In your theme, for the file: template/checkout/cart.phtml
Add the new heading along with other heading for cart items.
1 | <th><?php echo $this ->__( 'Comments' ) ?></th> |
In the file: template/checkout/cart/item/default.phtml
Add a new column
2 | <textarea name= "cart[<?php echo $_item->getId() ?>][comments]" rows= "3" cols= "20" ><?php echo $_item ->getItemcomment() ?></textarea> |
For Older version of Magento it would be:
2 | <textarea name= "cart[<?php echo $_item->getId() ?>][comments]" rows= "3" cols= "20" ><?php echo $this ->getItemItemcomment( $_item ) ?></textarea> |
Doing upto this. shoul show the text area added
The next step is to save the comment in DB, when customer update the cart.
So add a new field ‘itemcomment’ in the tabel ‘sales_flat_quote_item’. (For older version of Magento the table would be ‘sales_quote_item’)
Now we are going to add the code which will do the DB operation. For this we will need to modify the file:
app/code/core/Mage/Checkout/Model/Cart.php (Note: If you are planning to upgrade your Magento setup, copy this file to local & modify.)
Here we need to add some code to the function updateItems(), such a way that the function should now look like below:
01 | public function updateItems( $data ) |
03 | Mage::dispatchEvent( 'checkout_cart_update_items_before' , array ( 'cart' => $this , 'info' => $data )); |
05 | foreach ( $data as $itemId => $itemInfo ) { |
07 | $item = $this ->getQuote()->getItemById( $itemId ); |
12 | if (! empty ( $itemInfo [ 'remove' ]) || (isset( $itemInfo [ 'qty' ]) && $itemInfo [ 'qty' ]== '0' )) { |
13 | $this ->removeItem( $itemId ); |
17 | $qty = isset( $itemInfo [ 'qty' ]) ? (float) $itemInfo [ 'qty' ] : false; |
23 | if (! empty ( $itemInfo [ 'comments' ])) { |
25 | $write = Mage::getSingleton( 'core/resource' )->getConnection( 'core_write' ); |
27 | # make the frame_queue active |
28 | $query = "UPDATE `sales_flat_quote_item` SET itemcomment = '" . $itemInfo ['comments ']."' where item_id = $itemId "; |
29 | $write ->query( $query ); |
31 | $item ->setItemcomment( $itemInfo [ 'comments' ]); |
37 | Mage::dispatchEvent( 'checkout_cart_update_items_after' , array ( 'cart' => $this , 'info' => $data )); |
Showing the comment in Admin -> View Order
Add a new function getItemcomment() to the file below:
app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php
If you are on verstion 1.5 or later.. add it to the file below.
app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php
01 | public function getItemcomment( $item ) { |
02 | $itemId = $item ->getId(); |
04 | $write = Mage::getSingleton( 'core/resource' )->getConnection( 'core_write' ); |
06 | $query = "SELECT q.* FROM `sales_flat_order_item` o |
07 | LEFT JOIN `sales_flat_quote_item` q on o.quote_item_id = q.item_id |
08 | WHERE o.item_id = $itemId "; |
10 | # For older versions of Magento |
15 | $res = $write ->query( $query ); |
17 | while ( $row = $res ->fetch() ) { |
18 | if (key_exists( 'itemcomment' , $row )) { |
19 | echo nl2br ( $row [ 'itemcomment' ]); |
To add the comments column to the items edit the .phtml file below:
app/design/adminhtml/default/default/template/sales/order/view/items.phtml
Adding header for items to make it look like below:
4 | <th><?php echo $this ->helper( 'sales' )->__( 'Product' ) ?></th> |
5 | <th><?php echo $this ->helper( 'sales' )->__( 'Comments' ) ?></th> |
6 | <th><?php echo $this ->helper( 'sales' )->__( 'Item Status' ) ?></th> |
Adding Column with comments. app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
Add a column for item comments juts before status columns to make it look a like below.
3 | <td><?php echo $this ->getItemcomment( $_item ) ?></td> <!-- New column added for item comments --> |
4 | <td class = "a-center" ><?php echo $_item ->getStatus() ?></td> |
Doing upto this will show the comments column in the item table. It should look like image below.
Thanks!!!!! It works perfect on Magento 1.7 but the function getItemcomment() has to be placed in app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php
ReplyDelete:*
it's not working for me on magento 1.7. the comment value not inserting into database table field. can you please help!
ReplyDeleteNice. Its working good in magento1.7. I want to display it in sales order grid. Is it possible?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.
ReplyDeletebox file
This information was really helpful as i am associated with a company
ReplyDeleteand if someone want to Hire certified Magento developer
.please keep sharing in future.
I have read your article couple of times because your views are on my own for the most part. It is great content for every reader. magento eshop
ReplyDeleteI am jovial you take pride in what you write. It makes you stand way out from many other writers that can not push high-quality content like you. best bath towels
ReplyDeleteThe information you have posted is very useful. The sites you have referred was good. Thanks for sharing. Custom Writing Service
ReplyDelete