Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Cart
Priority:
Normal
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
17 Jan 2011 at 16:19 UTC
Updated:
14 Jun 2011 at 11:23 UTC
In the Cart view, the default configuration for the Line item label displays the product SKU.
After discussion with Ryan, this should be changed to:
* Label : Product Title
* Link : contextual link to where the product was added to cart.
Comments
Comment #1
rszrama commentedAs part of this issue, we need to preserve the display context of products added to the cart much like I'm doing for product fields that are rendered to display inside of a node.
Comment #2
rszrama commentedThis was fixed in stages...
Comment #3
pcambraJust after updating to the last changes I get these errors accesing the cart:
'Missing handler: field_data_commerce_total commerce_total field'
'Missing handler: field_data_commerce_display_path commerce_display_path field'
I think it's related to this commit.
Comment #4
rszrama commentedDid you rebuild your site from scratch? There's a new field that has to be added to the product line item type now, and I did have to rebuild the Views. I don't see any errors locally.
Comment #5
pcambraYes, I wiped out the database and reinstall from scratch, I get the errors both in the cart block and cart page.
I couldn't find in code none of the fields.
Comment #6
rszrama commentedThose fields are provided by Views itself. I'm running the latest version of Views as well. Have you updated it recently? You should see the display path field being created in the Product Reference module.
Comment #7
pcambraOk, I updated ctools and it solved the problem!
Comment #9
j0rd commentedWhile the fix in here did help, it needs to be expanded further.
I'll elaborate on my site so you understand the issue.
My site is a job listing site. Any user can post a job listing, and then purchase it, to enable it on the site. I have many job listings and 3 products. 30 days, 60 days, 90 days. I've attached these 3 products to each of the job listings that get created, via a product reference.
Now my issue arises in the commerce_cart_form view. I'd like the title of my line_items to be "$product->title listing for $node_product_display->title". This is currently not easy to do. I'll provide two methods I've attempted to rectify this with and how we can expand on Drupal commerce to allow this to happen.
#1. We're storing the product display node, which the product gets added from in $line_item. It can be found here $line_item->data[display_uri][options][entity][nid] . IMHO, this node needs to get added into the view by default, else it needs to be addable at least by adding a relationship. The data is already there, so this is feasible. It makes the commerce_cart_form much more flexible.
#2. I tried to be lazy and instead overwrite the $line_item title via hooks. Drupal Commerce while it kind of provides a hook for this, it's pretty hard coded. The hook that gets called is called via $line_item->type which means for products `commerce_product_line_item_title` is called. I can't hook in to override this and I feel I should be able to.
If there are other ways to accomplish what I'm trying to do, please let me know. But right now, I'm stuck. I really do not want to create 3 custom products for each node which gets created, 90% of which will never get purchased.
Comment #10
j0rd commentedPS. Do these hooks exist? Or are they just listed in the commerce_line_item.api.php to tease me?
Comment #11
rszrama commentedHey j0rd, glad to see you in the queue! So, to answer the quick question first, the .api.php is out of date as of beta4 apparently. I need to go update those... in fact, I think we may have combined those into a single presave a while ago. I'll have to get das-peter to weigh in, as we may have inadvertently removed them when we standardized on a single entity controller.
As to your specific issue, one thing you should be able to do is implement a custom title callback for your product line item type. I like they way you've built the site, and have recommended a similar approach to folks in the past. If you implement hook_commerce_line_item_info_alter(), you should be able to use a custom title callback that can inspect the line item, make sure it's for a job listing, and then return the appropriate title (or fallback to the normal title callback if not).
Hope that helps!
Comment #12
j0rd commentedAs for my feature request. I'll re-request since you did seem to touch on it. I did a little more digging last night and I think I figured out how line items work. I'll elaborate on how they can be improved.
In $line_item we have a field called "commerce_display_path" which I believe will always link back to the node path, which the product was added to the cart from.
Would it not be better to, instead of storing the path back to the display node, store the display nodes ID. Then we could add the path into the meta data, or a simple helper function to pull it out. I know the node ID is in there
Additionally, any view which has line_items in needs to get the commerce_display_path node exposed in views via a relationship. This way I'm able to use information from the $display_node, like $display_node->title in my commerce_cart_form. If I had this, I wouldn't need to be writing any code, it could all be done via views. Currently only the display_path is available and I think this is short sighted.
There are two issues which relate to $line_items & commerce_cart_form which I'll elaborate on. There's a feature request in #1 and #2 is already brought up in another issue queue.
#1. I have multiple 10 display nodes with the same product.
Let's say I'm using information from the display node to dynamically create my title for the line item. Titles will look something like this "Display node #1, Product #1".
Now I add "Display Node #1, Product #1" and "Display Node #2, Product #1" to my cart.
I'll end up with "Display Node #2, Product #1" with a quantity of 2 in my cart. This, while is a valid use case IMHO, but is not what I wanted.
I would prefer to have "Display Node #1, Product #1" with a Quantity of 1, and "Display Node #2, Product #1" with a Quantity of 1 in my cart instead.
Perhaps the best way to group over quantity would be to add another check over the line_item's titles. If they're not changed dynamically, they'll match and Drupal commerce will continue to function as expected. For those who are dynamically create line_item titles, two product line item's titles differ, then they will not be grouped over quantity.
I think this would be the desired out come for people who are doing what I'm doing. Having this additional flexibility allows me to only create 3 products for my site, instead of display node * 3 products for my site, which would be impossible to manage & maintain.
#2. I have 10 Products, all on the same display node.
I add "Display node #1, Product #1 " and "Display node #1, Product #2" to my cart.
These show up as two line items, both with links back to my display in the cart form.
When I click on the link in cart for "Display node #1, Product #2" in my cart, I'll be referred back to "Display Node #1, Product #1", since this is the default.
I've read of solutions getting implemented for this, which would do something like link back to "Display Node #1" with a #hash of the SKU. Then the display node would just need to be smart enough to load the proper Product. I would recommend this feature be added to improve user experience.
---
If I'm not "getting" something, please school me.