I'm attempting to create a view of products (as opposed to product displays), so all of my product colour variations show up as individual items in the view. However, the link to content is the product admin link (admin/commerce/products/x), not the product display node.

Comments

latulipeblanche’s picture

Stephanie,
Did you trouve a solution for this issue ?
I tried to get a view with the color variations of my colors and, like you, I didn't get the images linked to the product display of the product with that specific color.
Here is the item I put on drupalcommerce.org: http://www.drupalcommerce.org/node/466 .

rszrama’s picture

Ahh, hmm, missed this issue somehow. Product line items have a "display path" field on them used to link to the product display from which the product was added to the cart. The field should contain a path to the appropriate page, so if you include it in the View (but don't display it) you can add a link to the product title using that field's Token in the View. Not sure if that makes sense, but if an example helps, check out the default cart block View.

latulipeblanche’s picture

Ryan, I tried to get the view working but the "relationship" needed wasn't in the list, so I need to find out how to do it.

But I was wondering if you could help me with this, what is maybe a better way to get this done.

With the module "commerce_cart_options" I changed the dropDown-list in radio buttons. Next I put a image, representing the color to replace the radio-button. But this is don fixed.

<?php 
function commerce_cart_options_form_alter(&$form, &$form_state, $form_id) {
	if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
		$form['submit']['#value'] = t('Add to Cart');
		$form['product_id']['#type'] = 'radios';
		$form['product_id']['#options'][5] = '<img src="/path/to/image/product_images/colors/tshirt-red.jpg" />';
		$form['product_id']['#options'][6] = '<img src="/path/to/image/product_images/colors/tshirt-orange.jpg" />';
	}
}

What I need to finish the whole thing is how to get the link to be dynamicaly instead of fixed, relative to the url. The url looks like this : ~/content/tshirt . Do I need a Query in MySql or ...

Tnx a lot for your help (and for Commerce :) )
I feel that it I'm close to the end (I'm looking for this for some weeks now :( ) .

latulipeblanche’s picture

I don't get it work.
Not the view-way, not the module-way.
When I try to make a View, I don't get the "display-path" working with the "color-image".
When creating a view I made a view with fields :

Commerce Product: Product ID (Product ID)
Product: Type product (Type product)
Product: Image color

In no way I get the relationship "display-path".

I tried other views based on taxonomy-terms, commerce-line-item, commerce-product.

All this , just to replace the dropdown menu by representing images :( . Wish I was a better developer ...

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new43.38 KB
new1.85 KB

The "display path" is a field available when the base table is Commerce Line Item.

If you want to relate products to nodes referencing them, you need an inverse relationship, which as you've noticed is missing.
Here's a patch that implements it, and a screenshot.
I've made it exclude the relationship from line items to products because it doesn't seem useful, but that can easily be changed.

rfay’s picture

Wow, fantastic. Note that this may produce duplicate rows if there is more than one node presenting a product.

bojanz’s picture

Yup. And actually the join is currently wrong (it's joining products and nodes on nid = product_id), so standby for another patch...

bojanz’s picture

StatusFileSize
new2.54 KB

Here's a working patch. The previous one was missing a chunk.

latulipeblanche’s picture

@bojanz
I missed the IRC-message.

I was able to make a view showing the color-images. There is still one problem, that is that the image is linking to the admin-page. When I try to rewrite the results, I cannot chose "replacement patterns".
Token is installed ??

bojanz’s picture

@latulipeblanche
Works for me. Note that only the views fields that come BEFORE the field you're rewriting have their tokens shown in "Replacement patterns".
So add a hidden nid field before the image, and use it happily.

The patch seems to be working okay, so I've also created a branch for it in my sandbox:
http://drupalcode.org/sandbox/bojanz/1097750.git/commitdiff/21c8b14547b5...

liupascal’s picture

Would it be possible to make the link redirect to the product display with the right product's attributes selected ? Because if I added a Blue shirt rather than a Red and that the blue is the first product reference, then i'll end up redirected to the blue shirt which can be confusing. Might be related to #1082596: Implement unique URLs for particular products on product displays somehow ?

rszrama’s picture

Status: Needs review » Fixed
Issue tags: +dcsprint6

Patch appears to work just fine for me. : )

@liupascal - yeah, that would require functionality on product display nodes that just isn't there. We'll have to wait on a patch to the issue you linked before that could be considered.

khiminrm’s picture

Subscribe

Status: Fixed » Closed (fixed)

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

summit’s picture

Hi, Is this patch committed please?
greetings, Martijn

rszrama’s picture

Yep, it was committed last June.

FriedJam’s picture

StatusFileSize
new34.69 KB

Ignore me - issue resolved!

rszrama’s picture

Glad to hear it.

ontwerphuis’s picture

Hi Thanks this is exactly what i need to do.

@ bojanz how do I implement your patch? Sorry i'm still relatively new to drupal.

Thanks in advance

ontwerphuis’s picture

I'm running OS and using Terminal to install the patch but get the below error

$ patch < 1108180-inverse-relationship_0.patch
patching file commerce_product_reference.module
Hunk #1 FAILED at 592.
Hunk #2 succeeded at 829 (offset 202 lines).
1 out of 2 hunks FAILED -- saving rejects to file commerce_product_reference.module.rej

Any idea how to sort this?

rszrama’s picture

You can just update to 7.x-1.x-dev and run update.php.

Anonymous’s picture

Assigned: Unassigned »
Category: feature » task

[solved]
"Link to Product Display node from view of Products, not product admin"

I've just spent the last 2 days trying to solve this problem and running into terrible advice everywhere.

goal: click on image [as displayed in a block or page] from a view and go to the PRODUCT NODE page NOT the PRODUCT ADMIN PAGE!!!!

Through near-endless trial and error I FINALLY got this seemingly easy problem solved! I felt I should share the solution considering the pain it caused me. I hope it can help someone out there.
note: I was using Drupal 7.18, commerce kick starter 1.x. + I was trying to set up a jCarousel horizontal slider.

1. Create your view in the standard way: view of content type "product display".
2. In your new View config page: Establish a relationship with "Content: Referenced Product" * if you don't have this done, you'll have to google "how to add a product reference field to a product display NODE."
3. Once the relationship has been added, add FIELDS "Content: Path" and the (Image field you want to display) I used the 'Commerce: Product Image' field. Make sure the image field is ordered 2nd - after the "Content: Path" field. (apparently this is important or the token can't be used..)
4. CRITICAL!!!! click the "Content: path" field and thus open the "Configure field: Content: Path" configuration screen. In this screen -> click: exclude from display and click: "Rewrite Results".
Then click box (enable): "Use absolute link (begins with "http://")"
and APPLY
5. enter the configuration screen for your image field.
6. make sure the relationship drop-down menu has the relationship from step 2 selected.
7. Make sure the "Link image to" drop down menu is listed as "nothing"!!!!
8. Click "Rewrite Results"
9. Click: "Output this field as a link"
10. In the "Link Path" box put this: "[path]" (of course without the: " )
11. APPLY
12. SAVE VIEW
13. Reload in your browser and now your image should link to product display node and not the annoying product admin page.
I hope that helps.. I didn't get a full solution anywhere on any forum... so I hope this can help someone.
Peace.
p.s. sorry if my instructions are somewhat poorly written & organized, I'm in a hurry.
Good luck, get money!!
- Edacafa

rszrama’s picture

Yep, this is good. Another option is to use a view mode of the node type to render the desired injected product fields, including the product image, because a product image field when rendered into a node display will use the node's path for the "link to content" option as opposed to the product path.

yeiyei’s picture

Hi over there! Subscribing for this issue.
THANK YOU EDACAFA!!, save me a few more days of stuffing around views.

At this moment I´m using Drupal Commerce to develop a chilean marketplace for handracrafts (ikuna.cl). We are almost there, integrating chilean payment methods to drupal commerce. I`ve been trying to solve links from "product views" to "product display nodes" for 2 days, searching the "sort by product price (exposed)" in "Product Display View". The solution proposed by EDACAFA works also for sorting/filternig "Product Display Views" using "Products Fields". When the relationship is created the "Product Fields" appear as a possible selection in sort/filter config inside views.

MAIN ISSUE: "It is imposible to use product fields, such as price, to sort/filter a product display view".

Default Views:

  • "Product display view" with links to "product display nodes". The problem: no sorting/filtering by products fields.
  • "Product view" with links to "admin pages", but with filter/sorting based on product fields

Solution:

  • Follow EDACAFA´s steps >> The Re-write trick can be used with any field, not just the image (example: product image and product title both using the same rewrite rule linking to the display product node
  • When the relationship is created it is possible to sort/filter product display using product fields, and expose that to clients in the web

Problem:

  • This solution works great when there is a 1:1 relationship between products and product displays. If a product display have 2 or more products the link from the views looks just fine (with product titles and images corresponding the product), but all of these products pointing to the same/first product within the product display. For our BETA in March we will lunch with 1:1 relationship (product:product display), but if we want to move forward we will have to deal with the unique URL for every product inside a display: http://drupal.org/node/1082596. Will be exploring that in the nex few days
agileox’s picture

@EDACAFA Excellent Post! #22 ++++

Zac_JH’s picture

Hi

Is it possible to make this inverse relationship available to rules? I would like to force solr to re-index the related product displays when a product goes in or out of stock. I already have a rule that deals with the stock change making a product active or not and it would be great to a rules loop on the action list and force an index of the related product displays.

muschpusch’s picture

@rszrama: #23 actually works in kickstart but not in "plain" drupal commerce. I added the rendered node as "field" like in kickstart. Any idea what i could do wrong?

gianfrasoft’s picture

@FriedJam, how did you solve your problem? I have the same issue!

bmodesign’s picture

I needed to pull the product display link in as a regular field attached to my product, so I leveraged rules.

I'm sure there is a better way to tweak this, but here's how I made it into a field, because we love fields...
*my products have one display and are only listed on one display per product, so I'm not sure if multiple displays/products will wreck this*

  1. On your product variant, create a new field called display-link, field-type is a link. Display it as Title (linked), wherever you want it.
  2. I created a rule. Upon saving or creating a new commerce product. Conditions: Entity has field 'display-link'.
  3. first actions: Create a variable, URI type, from the commerce-product:field-product-node:0:url to be a variable named 'path_variable'. I think that 0 in my field declaration references the first display associated with the product. I think.
  4. second action: Set a data value, commerce-product:field-link-to-display:url is now 'path_variable'. This makes your new link field url the path of your product display!
  5. for the link title, third action: Set a data value, commerce-product:field-link-to-display:title is now 'commerce-product:title' so the new link field's 'title' is now the title of your product.

I then have to go in and re-save my products. I'm sure there's a bulk way to do this, but for my shop it took 5min. (not just re-saving the product display, but the actual products referenced too.)
I now have a field attached to my product, that links to my product-display that I can pull up as a linked field wherever I need it.

Here is my rule export.

{ "rules_product_display_url" : {
    "LABEL" : "Product Display URL",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Display", "URL" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_update", "commerce_product_insert" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_display_link" } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : {
            "type" : "uri",
            "value" : [ "commerce-product:field-product-node:0:url" ]
          },
          "PROVIDE" : { "variable_added" : { "path_variable" : "Set variable path" } }
        }
      },
      { "data_set" : {
          "data" : [ "commerce-product:field_display_link:url" ],
          "value" : [ "path-variable" ]
        }
      },
      { "data_set" : {
          "data" : [ "commerce-product:field_display_link:title" ],
          "value" : [ "commerce-product:title" ]
        }
      }
    ]
  }
}

Hope this helps someone.

VanD’s picture

I get this error

Integrity check for the imported configuration failed. Error message: Data selector commerce-product:field-product-node:0:url for parameter value is invalid..

I tried to recreate the rule myself and I don't have that selector "commerce-product:field-product-node:0:url" or anything close to that.

victor.bexelius’s picture

Issue summary: View changes

Hello,
been some frustrated days trying to sort this out with rules and views settings mentioned above. I did not manage to solve the issue with the information provided above - so I ended up with custom template coding. It may not be the best solution, but it gets the job done and Im happy with it.

1. I've created the view for the related products block. In here I am setting the relations and filters as mentioned above. If you are lazy or just had enough googling this issues let me point out the most important keys:

1.1 Advanced settings in view:
Contextual filters: Nid -> provide default value -> Content ID from URL
Relationships: Content: Related products -> Require this relationship

1.2 Fields added to view:
(Products referenced) Commerce Product: SKU <--- this one is the key to make all this work.
+ any other fields you require

1.3 My view export (for your convenience)

$view = new view();
$view->name = 'related_products';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Related products';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['link_display'] = 'custom_url';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '2';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['pager']['options']['tags']['first'] = '« Första';
$handler->display->display_options['pager']['options']['tags']['previous'] = '‹ Föregående';
$handler->display->display_options['pager']['options']['tags']['next'] = 'Nästa ›';
$handler->display->display_options['pager']['options']['tags']['last'] = 'Sista »';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['default_field_elements'] = FALSE;
/* Relationship: Content: Referenced products */
$handler->display->display_options['relationships']['field_product_related_product_id']['id'] = 'field_product_related_product_id';
$handler->display->display_options['relationships']['field_product_related_product_id']['table'] = 'field_data_field_product_related';
$handler->display->display_options['relationships']['field_product_related_product_id']['field'] = 'field_product_related_product_id';
$handler->display->display_options['relationships']['field_product_related_product_id']['label'] = 'Products referenced';
$handler->display->display_options['relationships']['field_product_related_product_id']['required'] = TRUE;
/* Field: Field: Title */
$handler->display->display_options['fields']['title_field']['id'] = 'title_field';
$handler->display->display_options['fields']['title_field']['table'] = 'field_data_title_field';
$handler->display->display_options['fields']['title_field']['field'] = 'title_field';
$handler->display->display_options['fields']['title_field']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['title_field']['label'] = '';
$handler->display->display_options['fields']['title_field']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title_field']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['title_field']['type'] = 'text_plain';
$handler->display->display_options['fields']['title_field']['settings'] = array(
  'title_style' => '_none',
  'title_link' => '',
  'title_class' => '',
);
$handler->display->display_options['fields']['title_field']['field_api_classes'] = TRUE;
$handler->display->display_options['fields']['title_field']['link_to_entity'] = 0;
/* Field: Commerce Product: Price */
$handler->display->display_options['fields']['commerce_price']['id'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['table'] = 'field_data_commerce_price';
$handler->display->display_options['fields']['commerce_price']['field'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['commerce_price']['label'] = '';
$handler->display->display_options['fields']['commerce_price']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['commerce_price']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['commerce_price']['click_sort_column'] = 'amount';
$handler->display->display_options['fields']['commerce_price']['settings'] = array(
  'calculation' => '0',
);
/* Field: Commerce Product: Add to Cart form */
$handler->display->display_options['fields']['add_to_cart_form']['id'] = 'add_to_cart_form';
$handler->display->display_options['fields']['add_to_cart_form']['table'] = 'views_entity_commerce_product';
$handler->display->display_options['fields']['add_to_cart_form']['field'] = 'add_to_cart_form';
$handler->display->display_options['fields']['add_to_cart_form']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['add_to_cart_form']['label'] = '';
$handler->display->display_options['fields']['add_to_cart_form']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['add_to_cart_form']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['add_to_cart_form']['show_quantity'] = 0;
$handler->display->display_options['fields']['add_to_cart_form']['default_quantity'] = '1';
$handler->display->display_options['fields']['add_to_cart_form']['combine'] = 0;
$handler->display->display_options['fields']['add_to_cart_form']['display_path'] = 0;
$handler->display->display_options['fields']['add_to_cart_form']['line_item_type'] = 'product';
/* Field: Commerce Product: Images */
$handler->display->display_options['fields']['field_images']['id'] = 'field_images';
$handler->display->display_options['fields']['field_images']['table'] = 'field_data_field_images';
$handler->display->display_options['fields']['field_images']['field'] = 'field_images';
$handler->display->display_options['fields']['field_images']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['field_images']['label'] = '';
$handler->display->display_options['fields']['field_images']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_images']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['field_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_images']['settings'] = array(
  'image_style' => 'thumbnail',
  'image_link' => '',
);
$handler->display->display_options['fields']['field_images']['delta_offset'] = '0';
/* Field: Commerce Product: Buy button color */
$handler->display->display_options['fields']['field_field_btncolor']['id'] = 'field_field_btncolor';
$handler->display->display_options['fields']['field_field_btncolor']['table'] = 'field_data_field_field_btncolor';
$handler->display->display_options['fields']['field_field_btncolor']['field'] = 'field_field_btncolor';
$handler->display->display_options['fields']['field_field_btncolor']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['field_field_btncolor']['label'] = '';
$handler->display->display_options['fields']['field_field_btncolor']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_field_btncolor']['element_default_classes'] = FALSE;
/* Field: Field: Header color */
$handler->display->display_options['fields']['field_colorbox']['id'] = 'field_colorbox';
$handler->display->display_options['fields']['field_colorbox']['table'] = 'field_data_field_colorbox';
$handler->display->display_options['fields']['field_colorbox']['field'] = 'field_colorbox';
$handler->display->display_options['fields']['field_colorbox']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['field_colorbox']['label'] = '';
$handler->display->display_options['fields']['field_colorbox']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_colorbox']['element_default_classes'] = FALSE;
/* Field: Commerce Product: Link */
$handler->display->display_options['fields']['view_product']['id'] = 'view_product';
$handler->display->display_options['fields']['view_product']['table'] = 'commerce_product';
$handler->display->display_options['fields']['view_product']['field'] = 'view_product';
$handler->display->display_options['fields']['view_product']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['view_product']['label'] = '';
$handler->display->display_options['fields']['view_product']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['view_product']['text'] = 'Läs mer';
/* Field: Commerce Product: SKU */
$handler->display->display_options['fields']['sku']['id'] = 'sku';
$handler->display->display_options['fields']['sku']['table'] = 'commerce_product';
$handler->display->display_options['fields']['sku']['field'] = 'sku';
$handler->display->display_options['fields']['sku']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['fields']['sku']['label'] = '';
$handler->display->display_options['fields']['sku']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['sku']['link_to_product'] = 0;
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Filter criterion: Commerce Product: Status */
$handler->display->display_options['filters']['status_1']['id'] = 'status_1';
$handler->display->display_options['filters']['status_1']['table'] = 'commerce_product';
$handler->display->display_options['filters']['status_1']['field'] = 'status';
$handler->display->display_options['filters']['status_1']['relationship'] = 'field_product_related_product_id';
$handler->display->display_options['filters']['status_1']['value'] = '1';

/* Display: Related Products */
$handler = $view->new_display('block', 'Related Products', 'block');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;

2. I've created my own TPL file for the block containing my related products.

Example name of tpl file: views-view--related-products--block.tpl.php

The code for looping out related products in this TPL

<?php if(isset($view->style_plugin->rendered_fields)):?>

<?php foreach ($view->style_plugin->rendered_fields as $delta => $item): ?>

** Here we can loop out all the line-items stored in $item. Example <?php print $item['sku'];?> and html markup **

<?php 
// ## God damn long fix for getting refered product alias! ##
// Stored in $parentNodeAlias
		 	
// First we get the SKU from the hidden field we added in the view
$sku = $item['sku'];
// Then we load the product via sku
$product = commerce_product_load_by_sku($sku);
$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node', '=')
->fieldCondition('field_product', 'product_id', $product->product_id, '=')
->range(0, 1);

// Then we get the URL alias (you can print out $parentNodeAlias in a link)
if ($result = $query->execute()) {
$parentNodeId = array_keys($result['node'])[0];
$parentNodeAlias = drupal_get_path_alias('node/'.$parentNodeId);
}
?>

And here we finally print out the Node alias, example:
<a href="/<?php print $parentNodeAlias; ?>" title="<?php print t('Read more');?>"><?php print t('Read more');?></a>

<?php endforeach; ?>

<?php endif;?>

Hope this helps anyone out there!

Off topic / Personal tips:
By the way - if you are trying to add items to cart from this related block AND using AJAX for this related block view: You will get an AJAX JSON response instead of the product being added to the cart. I have not resolved this issue yet - but the issue lies within the form action of the add to cart button -> as it gets fubared by the containing form that capsules the whole block to enable the AJAX-view -> thus changing form action of the add to cart button to /view/ajax and fubares the page out.

Update: http://xandeadx.ru/blog/drupal/645 post fix for this issue - but I have not had any luck with it.

Best regards //

Victor

pun_pun’s picture

edacafa, thank you for your solution #22! You saved my nervous system. :)

tomfilepp’s picture

All of these solutions are great but, why not just implement this as a default behavior? Why would you want it to default to the admin url at all? Seems like this is overcomplicating a simple thing.

Road Kill’s picture

The solution 22 works but only if you have a single product but if you are using product variations then you are out of luck.

If I understand this correctly the patch in 8 has been committed but I cannot find a back reference or reverse reference option in the latest dev. I hope a solution will become available in a future release as this limits builds to content type displays through the view.

Possibly providing a product carousel for product variations on the field would be one solution for variations.

xstanley’s picture

I was facing this problem also in the latest Kickstart 2 version, so after hours of investigating I was able to prepare these detailed steps how to solve it:

  1. In Views under 'Advanced' and the 'Relationship' heading choose 'Add', and find and select 'Content: Referenced Product' (if adjusting a cart form view, then select 'Commerce Line item: Product'). Check the 'Require this relationship' checkbox.
  2. Now, under 'Fields' heading add a field 'Content: Path' (in case of the cart form view, add 'Commerce Line item: Display path'). 'Exclude from display' this field and arrange it to be the first field (it is important to have this field above the image field in order to be able to use its [path] token (see point 3)). If you have a multilingual page, check 'Use absolute link' under 'Rewrite results' (matters for the 'Content: Path field' only).
  3. Finally, add the 'Product: Images' field. Link it to Nothing. Under 'Rewrite results' choose 'Output this field as a link' and use the token [path]. If you are facing the problem also with other fields, apply this solution also to them.

Source: Me and https://drupalcommerce.org/discussions/556/product-image-views-link-prod...

tuccio’s picture

Not sure if I am missing the obvious, but I am trying to create a simple Commerce Product view and want to add a link to the node(s) referencing each product, but cannot find any inverse relationship to the node referencing the product. It should be available by now, correct?

loparr’s picture

@tuccio
You would want to add another relationship that is made available by adding Products referenced by commerce_product.
Next add: Node referencing products from field_YOURFIELD. This way you can get data form the referencing node.

loparr’s picture

Anybody solved the issue with duplicates in cart if multiple product displays are referring to one product?
EDIT: after looking to the db, it looks like it is not possible.

webdevdoc’s picture

Ok, Maybe I am missing something so my question is really simple.

How would I make a view to show products on the frontend to anonymous users. This view will include a list of product fields to include a product title and an image. Upon clicking on a product title or clicking on the product image the anonymous user will be taken to the product detail page where they can see all the other fields in the product including the price and an add to cart link.

DOH! - So I am the type to just jump right into things, I started working with products but did not realize that you need to create a new content type for products as a node and then add a product reference field to link the front end node up with the back end product. Quite unusual and was really frustrated trying to figure this out initially and then was like, WTF? why was it created this way, THEN after working with it and thinking about it, I realized that it opened up a world of possibilities, i.e., linking products sold at multiple physical locations (nodes) with 1 product in the back end. I am continuing to explore. Interesting configuration.