I used Commerce Kickstart's install profile to create the site.
I feel that this may be due to my lack of understanding the product / display relationship. Any help would be greatly appreciated.
The shopping cart views are unchanged from their installed state. Each product pulls a display path from a line item relationship.
Whenever I add a product from the product display page, it creates a product link in the shopping cart. But when I add a product from views that I have created it adds the product, but does not create the product link.
The views that I have created are views of product displays fields with additional product fields that are pulled by a product relationship. This is where I become confused. The view that I have created recognizes the relationship between product / display, because it populates the additional fields (image, price, add to cart form).
So, where is communication breakdown? Why isn't the shopping cart view finding a display path for the products?
Comments
Comment #1
rszrama commentedThe problem is that the Add to Cart form Views field doesn't have any way of knowing what node any particular product is displayed on. The primary way around this in a View, though, is to render the actual product display node into the View using a display mode that just shows the node's Add to Cart form. The rendering process there ensures the form has the necessary context to link the product line item to the appropriate "display_path".
Comment #2
philipbe commentedThat makes sense, considering that a product may be referenced in multiple displays. But when I go to change the view, the only Add to Cart field that I see available is from referenced products - (Referenced Product) Commerce Product: Add to Cart form. Am I missing the field for a Content: Add to Cart form? Or do you mean that I can only use views that display nodes (and consequently the Add to Cart form from that node's product reference) ?
The views that I've created are filtered by content type --> product display, should I be able to add a field for that product display's Add to Cart form? Or is my understanding of the product /display relationship still flawed?
Comment #4
gmopinillosv commentedHello there
This issue is the most similar to my case but I realized the next. When I add a new product and I add to cart it, not show the link "view product" . But when I edit that product and modify something on product variation and save again. The link "view product" appears in Shopping cart.
Somebody could tell me what is happening? Is it a bug of the commerce kickstart ? or Am I doing something wrong?
Any help will be highly appreciated. Thanks.
Comment #5
rszrama commentedIt sounds like you're having an issue with Commerce Kickstart 2, right? If so, post a new issue in that queue.
Comment #6
elpino commentedThe Commerce Product: Add to Cart form field has the following checkbox option:
Link products added to the cart from this page display to the View's path.
Checking this produces the following errors
could a similar checkbox be added that sets the path by whatever replacement token, so the product display path can be referenced?
I have installed Commerce 7.x-1.7
Comment #7
Sammii commentedI am having this issue as well and it is actually not related to Kickstart.
If I add a product to my cart from the Product Display node, then view my Cart, the product name links to the Product Display node.
However, on a View page that lists Product Display nodes with the field (Products referenced by field_course_reference) Commerce Product: Add to Cart form, if I add the product to my cart using that button, the product name has no link in the cart. The ideal behaviour would be for the product name to always link to the Product Display node in the cart, regardless of how it was added to the cart. On my website I have both methods for users to buy products, so it makes for inconsistent output in the Cart.
Is there a way to configure the View to have the product linked to its Product Display node in the Cart? Seems like it should be possible considering the necessary Relationship is already defined in the View?
Comment #8
rszrama commentedThe issue is the Views field handler that builds that Add to Cart form has no knowledge of the node that might be displaying that product. Instead you should use the Views field that corresponds to the product reference field on the node, rendering that as an Add to Cart form so it gets the appropriate context to set the display_path on the line item.
Comment #9
ruchirashree commentedYes display_path is missing in Drupal Commerce when you add products to cart using some list of products created by view.I have solved my problem using hook_form_alter, for the add_to_cart form.
I have used below code to set display_path when product is getting added on the list page using hook_form_alter:
$product_id = $form['line_item_fields']['#entity'] ->data['context']['product_ids'][0];
$query = new EntityFieldQuery;
$result = $query->entityCondition('entity_type', 'node', '=')
->fieldCondition('field_product', 'product_id',$product_id, '=')
->execute();
$node_id = '';
foreach($result['node'] as $key=>$value){
$node_id = $key;
}
$form['line_item_fields']['#entity'] ->data['context']['display_path'] = 'node/'.$node_id;
It solved my problem.Hope this will help someone.
Comment #10
vlad.dancerHi, I've bumped too into this issue.
Thanks, @ruchirashree, this was saved my time.
Comment #11
sagacity commentedThe explanation from @rszrama was a little bit too short for me, so I needed a long time to try the correct way. Maybe there's someone with a similar problem, so I try to explain it more detailed:
There are two ways to show the add-to-cart-form.
(1) Add the field "Commerce Product: Add-to-cart form" which is not really working, because of the missing link or
(2) add the reference field of the whole product (e.g. field_product), which is working correctly. After adding the field you have different opportunities, e.g. showing the whole product, but you also can show the add-to-cart-form. This form is (in standard configuration) for the whole product and also shows all variations in a select field. So it's important to mind the "Multiple Field Settings". In my case I wanted to show every product variation as single product, so I had to uncheck the box.
Hope it helps someone in finding the solution faster :)
Comment #12
katin commented@ruchirashree thanks so much for the code, man. Helped me out and really saved me some time!