In `Shopping cart form (Commerce Order)` view created by `Commerce`, product titles don't link to their nodes. How can I fix this?

Comments

scottrigby’s picture

Status: Active » Fixed

Here's how to do this:

  1. Edit the view
  2. In the view, add a 'Commerce Line item: Display path' field, and set to 'exclude from display'
  3. Rearrange the field order so the display path is above 'Commerce Line Item: Title (Title)'
  4. Edit the Title field, and click to expand the 'Rewrite results' fieldset
  5. Check the box 'Output this field as a link'
  6. Add '[commerce_display_path]' replacement in the 'Link path' (this should be in the list of 'Replacement patterns' below)
  7. Save the view

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

rszrama’s picture

Thanks for pitching in on support, Scott. : )

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

szymon.l’s picture

and...

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?

szymon.l’s picture

Issue summary: View changes
Status: Closed (fixed) » Active
szymon.l’s picture

ok, 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 ;)

rszrama’s picture

Status: Active » Closed (fixed)

This 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.

szymon.l’s picture

folarin’s picture

This 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.

szymon.l’s picture

Thank 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!

folarin’s picture

Yes 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.

casti2525’s picture

Just 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.

rolok’s picture

casti2525,

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

rolok’s picture

Okay, 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

sillo’s picture

Im not getting this relation at all.. none of the relations you say, appear to me.
Do you mind sharing your Views code?