Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In `Shopping cart form (Commerce Order)` view created by `Commerce`, product titles don't link to their nodes. How can I fix this?
Comments
Comment #1
scottrigbyHere's how to do this:
As long as the product was added to cart from a product display node, the title should now link there.
@see #1212070: Provide entityreference field "Product display" instead of /additionally to "Display path" on line item
Comment #2
rszrama CreditAttribution: rszrama commentedThanks for pitching in on support, Scott. : )
Comment #4
szymon.l CreditAttribution: szymon.l commentedand...
what if the product was not added through product display, but from e.g. product list or "featured products" block?
how to make cart line item link to product display?
Comment #5
szymon.l CreditAttribution: szymon.l commentedComment #6
szymon.l CreditAttribution: szymon.l commentedok, I get that if you add product to cart via view, in field settings of "add to cart" you can select a box to add the source view path to commerce line item display path, that makes products in cart link to views etc. if the view shows random products, or a lot of them, then this behavior is.. just wrong.
Is there a good way to make cart line item ALWAYS link to product display? With or better without using custom php field in this view?
ps. I assume there can be a problem, if single product is referenced by multiple product displays.. (i assume this may happen in some cases or when using bundles or so..)
Help would be appreciated ;)
Comment #7
rszrama CreditAttribution: rszrama commentedThis would be a good question for http://www.drupalcommerce.org/questions. If you post there and give me a link, I'd be happy to pitch in with some advice.
Comment #8
szymon.l CreditAttribution: szymon.l commentedhttp://www.drupalcommerce.org/questions/12521/how-link-line-item-commerc...
Comment #9
folarin CreditAttribution: folarin commentedThis can also be resolved by simply adding ID of Product to the view and use it
to generate link to the actual Product.
Assuming you are using Drupal 7, you can achieve this by carrying out these two tasks explained below:
Task 1: Add CommerceLine Item: Product (to Shopping cart block view) by following these steps below:
Step 1: Click Add button in front of FIELDS
Step 2: Check the Commerce Line item: Product checkbox
Step 3: Click Add and configure fields
Step 4: Check Exclude from display
Step 5: Choose Title(link) under Formatter
Step 6:
Under REWRITE RESULTS section,
Check Rewrite the output of this field and enter [commerce_product-product_id] under Text.
Note that under REPLACEMENT PATTERNS section, these two arguments are true:
[commerce_product] == Commerce Line item: Product
[commerce_product-product_id] == Raw product_id
Step 7: Click on Apply to complete Task 1.
So what we are really doing under Task 1, is to add Commerce Line item: Product to the view and replace it with Raw product_id
Task 2: Edit Commerce Line Item: Title (in Shopping cart block view)
Step 1: Click on (Line Item) Commerce Line Item: Title under FIELDS
Step 2: Under REWRITE RESULTS section, change Link path to products/[commerce_product]
Step 3: Click on Apply to complete Task 2.
Note: products is the path to products page while [commerce_product] now contains the Product ID so that the final
output link will look like for example products/2.
Comment #10
szymon.l CreditAttribution: szymon.l commentedThank you folarin!
While your solution (taken as it is) did not work for me, I was able to modify it according to my needs.
Basically my products don't have path:
products/id
but
products/title-of-products
so I did not have to add any field to cart view, I have only modified the commerce line item : title, so it was outputted as link to "products/[line_item_title]" with replacing space with "-" and lowercase..
anyway
Thank you! works perfect!
Comment #11
folarin CreditAttribution: folarin commentedYes szymon.i, you are right, your case is straight forward as the title is already there in the view. My solution will work for someone using product ID in the url, also i forgot to mention that CommerceLine Item: Product need to appears before Commerce Line Item: Title in the view under the Fields section.
Comment #12
casti2525 CreditAttribution: casti2525 commentedJust add a relationship for "Commerce Product: Referencing Node". Now the nid will be available to you in fields so you can build a path back to a node. This worked for us since all of our products were displayed in bundles.
Comment #13
rolok CreditAttribution: rolok as a volunteer commentedcasti2525,
Can you please explain?
I don't see the relationship "Commerce Product: Referencing Node" in the "shopping cart" view...
I stuck with it ... All the other solutions did not work for me
Thanks in advance
I would appreciate any help
Comment #14
rolok CreditAttribution: rolok as a volunteer commentedOkay, never mind, I did something different from what is mentioned in here, and it works great.
And maybe it will help someone else ... So what I did was:
1.in my products views I added the field "NID" and exclude it from display.
2. in the "shopping cart" view - i added 2 more Relationships:
"Commerce Line item: Product"
After that I added:
"Commerce Product: Referencing Content"
After I made Those changes In that order
I could add "Content: Nid (Nid)" field at the top (above the title Field),
Again I Exclude from display and Rewrite the output of this field as "Text" and put "[nid]" and save it.
After that I edited the "Title" field, REWRITE RESULTS, Output this field as a link and there i add "node/[nid]".
and that's it
Hope this helps
Comment #15
sillo CreditAttribution: sillo commentedIm not getting this relation at all.. none of the relations you say, appear to me.
Do you mind sharing your Views code?