2
Answers
Vote up!
1
Vote down!

How to link: "(Line Item) Commerce Line Item: Title (Product)" to product display

If we add a product to cart via product display page, than we have "Commerce Line Item: Display path" populated with the path to display node. So we can link it in the cart view (by overriding field output and by using replacement tokens).

This is fine and works ok.

Now thing get messy (in my opinion) when we add product to cart using different page than product display.

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.

Question:

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

pps. this question was originally posted here: https://drupal.org/node/1542330#comment-8279727

Asked by: szymon.l
on December 16, 2013

2 Answers

Vote up!
3
Vote down!

So the root issue is that we need to know the context of the Add to Cart form's display to link to the proper URL. Views allows you to establish relationships from anywhere, creating Add to Cart forms that aren't tied to the typical product display at all (like yours). This means the display_path should be populated to the URL of the View itself instead of the product display through which the relationship was established.

If you want it to always link to the product display, you need to make sure the Add to Cart form is being displayed within the context of the product display. This means instead of using the "Add to Cart form" Views handler you should instead add the product reference field to the View and format it so that it's using the Add to Cart form display formatter.

The alternative is to set the URL yourself through Rules or a hook that loads the appropriate product display node and inserts a link to it.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Dec 16, 2013
Vote up!
1
Vote down!

The first solution worked for me, thank you Ryan.

ps. I have also Commerce Wishlist module installed and exactly the same problem, which does not get fixed with this, but I assume this deserves another question?
(there is no link to product display at all (no matter where from it was added, and no product title, only SKU)

Answer by: szymon.l
Posted: Dec 17, 2013