Vote up!
Vote down!

How can I change how a line item displays in the cart / checkout?

I'm building a store with a lot of promotions in it, and some items in the shopping cart have a linked promotion. I want to show this promotion on the checkout page (before the order completion).

Is there a way to change the title of the product on this checkout page?

It's a shop without any visible prices. The total amount of the order is calculated on the servers... (it's a complicated process). So there is nothing to worry about that.

I just want to display the pink text in a proper way (http://i.imgur.com/5cPG78Q.png). Any ideas?

Asked by: michielkenis
on July 21, 2013

2 Answers

Vote up!
Vote down!

You have several options at your disposal. The first and likely most straightforward is to simply enrich your line items with additional fields that point to these promotions and then edit the View to show those fields. It appears you've already edited the View to remove things like pricing, so it should be easy enough for you to add in an additional custom field that you've populated on the Add to Cart.

Another option would be a custom line item title callback. Using hook_commerce_line_item_type_info_alter(), you can specify an alternate line item title callback that is capable of displaying the offer along with the product title. The one drawback of this is that the promotion would be included in links that use the line item title to connect the item in the cart to its display page.

Finally, you might consider a custom Views field. To render the field, you could examine the contents of the $line_item->data array (or perhaps its price components) to find what offer applies and render it accordingly. This is probably the most future proof but also requires the most coding; I just like that you won't have to manage static storage of the promotion type in some field on the line item like you would if you go with the first option.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Jul 22, 2013
Vote up!
Vote down!

Hi Ryan,

Thanks for your reply!
I've tried all of the suggestions you suggested, but no luck here...

You're first suggestion to add a field didn't work out since my database is a bit more complicated then you assume. I have a lot of custom tables with all the required info.

The second solution you proposed didn't work out either... The hook you mentioned did not show me anything linked to the line items. All I got was some info about the view.

So, I went with the 3th solution. I've successfully implemented my custom table and fields in the views with the hook_views_data(), but whenever I want to show my custom field, the view won't show me anything at all (even though my cart is filled with line items...)
Do you have any suggestion about this last issue?


Answer by: michielkenis
Posted: Jul 30, 2013