This separation between Product and Product Display node has opened up a whole can of worms, although I'm sure there must have been some good reason for doubling the work of those who have to add 1000 product items and then another 1000 product nodes and then to match each single one of them.

By the way that's not how Amazon does it - there it seems to be some kind of simple Node-Reference which loads the product variant through ajax. Anyways.... (BTW, if there's an ongoing thread requesting to switch Commerce back to 1-node, please post a link cause I'd love to offer my 2 cents/pence as to why it should be done.)

Latest in the series of these "worms from the can" is that if you try adding to cart a product from views, in the Shopping cart it will appear as a text, whereas if you add to cart from the product page, then it will appear as a link. How do we deal with that?

Thanks?

Comments

rszrama’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Category: bug » support

If the Cart module can determine the context of the Add to Cart form when you add the product to the cart, it will add a link to it using the display path field on the product line item. Normally it pulls this from the node the Add to Cart form was displayed on. If you've just used the "Add to Cart form" Views field handler, then it may not be able to determine a reliable path to link the resulting line item to. The way around this within Views is to actually render the node in a Views field using a view mode that includes the Add to Cart form.

That said, there are dozens of threads discussing the product / product display issue if you search for them. It comes up all the time, and I really do try to communicate about it as much as humanly possible. For architectural reasons, there's no way we're ever going to revert to a hard relation to nodes with product data. If you review some of the threads and see exactly what it gains us, I can't imagine you'd think the problems that created are worth going back to. The usability issues are much easier to solve than the architectural issues, but no one has glibly decided to duplicate everyone's work. There are modules like Commerce BPC that aid in the bulk creation of products and assignation to product displays, even if they aren't perfect yet. I also have a contrib in the works to embed the full product form inside the node form (incidentally making it function much like you're suggesting without the mess we got into with SKU "adjustments" in Ubercart and multiple nodes per product).

In short - there are solutions and more solutions in development in contrib, but the core data model is fairly well set. We've tested and tried it in a variety of situations and haven't encountered a use case where it doesn't work, while we've had plenty where the former model wouldn't.

Back to the original issue, the real question is how have you built this View? Perhaps export it so we can reproduce the problem; usually I'd expect the line item to just link back to the View page itself.

cyntaur’s picture

StatusFileSize
new4.22 KB

Hi: I'm wondering if someone can clarify the following for us laypeople:
"The way around this within Views is to actually render the node in a Views field using a view mode that includes the Add to Cart form."

We're having the same issue. Attached is the code from the view:

nmc’s picture

@rszrama: would you mind explaining how the 'display path' is built when the Cart view is rendered and why it may not be rendering some display path URLs?

I'm using a modified version commerce_add_to_cart_extras module whereby I'm trying to link the line item to the product display node by customizing the 'display path '. I can see it being added correctly when I inspect the $line_item object in save function of CommerceLineItemEntityController. But the line items in my cart still aren't linked and when I output the display path as a field in the view, it's empty.

Note: I haven't modified any code in commerce core other than to insert devel print statements to try and figure out what's going on. My code modifications are to the commerce_add_to_cart_extras module.

liupascal’s picture

@cyntaur in #2 :
The display path represent the _product display node_ from where you added the product to the cart.
If you added the product in a cart without being in a product display node, there is no way the system can define what node should be your display path, since you could potentially have more than 1 node referencing the product.

In other word, in a real store for instance : you could find the same product in multiple shelves (say an Ipod can be on the APPLE's PRODUCT SHELF _and_ on MP3 PLAYERS SHELF, to be sure you won't miss it ...). If you take it from APPLE's PRODUCT SHELF, the "display path" is APPLE's PRODUCT SHELF as this is where you took it from, same thing for MP3 PLAYERS SHELF.... Now imagine you're not taking it from here directly, but ask a salesman to get one from the stock warehouse : you're not following the regular "path" to get this product, so if I ask you to put the product back from where you took it, how do you do ? You can't since you're not allowed to get in the stock warehouse.

In this example : APPLE's PRODUCT SHELF and MP3 PLAYERS SHELF are 2 different product display referencing your iPod, and asking the salesman is using another way to put the product to the cart (order edition UI, or commerce_add_to_cart_extras)

When rszrama in #1 said

"The way around this within Views is to actually render the node in a Views field using a view mode that includes the Add to Cart form."

: if you create a view that renders product displays (which are referencing products), then you'll be able to have you display path filled up correctly, as the add to cart button have a reference.

Hope it helps !

googletorp’s picture

You can get a long way by using hook_commerce_product_uri. It will allow you to define the url for products.

summit’s picture

Hi @cyntaur did you solve your view to get the fields manipulative renderer in views? Instead of the complete entity?
I am only possible to get the complete node-object to be renderen in views through "content: rendered content" field.
I would very much like to be able to have the rendered views (products fields) individualy "formattable" like normal views fields.

EDIT: Hi. I solved my situation by using views displays of products. You can choose standard - full node - teaser etc.. and enable the appropriate fields!

greetings,
Martijn

mindhunter75’s picture

Subscribing!

JockeL’s picture

If anyone is interested, this can be solved by replacing the token from the display path, with the path from the node itself. To do this you need to add two more relationships to the view:
Commerce Line item: Referenced product - Use relationship Line Item.
Commerce Product: Node referencing products from field_product - Use relationship Product.

Then add the field Content: Path using the relationship Node referencing products from field_product and exclude it from display. In rewrite results, check Use absolute link (begins with "http://"). Rearrange the field to the top to make the token available to other fields.
Edit the field (Line Item) Commerce Line Item: Title (Product) and in rewrite results, replace [commerce_display_path] with [path].
Remove the field (Line Item) Commerce Line item: Display path.

rszrama’s picture

Status: Active » Fixed

Great, thanks for the solution. Using Views tokens is indeed the way to accomplish something like this, and your walkthrough is very helpful. : )

nmc’s picture

@JockeL: would you mind posting a bit more detail on how to get the view to work? I'm not able to replicate/follow the last part of your instruction:

Edit the field (Line Item) Commerce Line Item: Title (Product) and in rewrite results, replace [commerce_display_path] with [path]. Remove the field (Line Item) Commerce Line item: Display path.

I can't find the [commerce_display_path] token to replace

JockeL’s picture

@nmc: When you edit the field (Line Item) Commerce Line Item: Title, in Rewrite results you should find that Output this field as a link is checked and uses the token [commerce_display_path] in the link path input. Replace this with [path]. If Output this field as a link is unchecked, you can just check it to reveal the options for the link and add the token to the link path input.

Status: Fixed » Closed (fixed)

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

rphillipsfeynman’s picture

You are a genius @JockeL . Thanks very much.

geek-merlin’s picture

Just a note: The solution in #8 brings us ALL nodes that relate to a given product.
So it will not work in a multiple-displays-per-product setting.

geek-merlin’s picture

Title: Items added from views do not display in Shopping cart block as links » Make views addtocart field use current page path as display path fallback
Category: support » feature
Status: Closed (fixed) » Needs review
StatusFileSize
new1.45 KB

Patch with a cleaner solution flying in:
If the view does not have a path, take current request path.
Trivial patch that i already use in prod.

Hey, i could make a really cool amazon-style addtocart table and still have my cart backlink to display.

matsjacobsson’s picture

Hi,

First I was stoked about #8 solution until I realized it didn't work with multiple-displays-per-product settings (as Axel pointed out...).

And there is already tickbox for the "Add to Cart form" that lets you link to the current path (Link products added to the cart from this View to this View's path if displayed as a page.), which is what patch #15 was doing.

Have anyone got this to work with multiple-displays-per-product settings?

Cheers! /Mats

rszrama’s picture

Title: Make views addtocart field use current page path as display path fallback » Allow the Add to Cart form Views handler to use the current path as the display_path for products in the cart
Status: Needs review » Fixed

Thanks for the patch, Axel, sorry it's taken so long to respond. I committed a slight variant - I basically wanted to continue to make the link be governed by the display_path option in the field handler. I've just expanded it to support linking to current_path() if the display plugin isn't page. There are legitimate reasons for a product to be added to the cart without a link, so we can't safely change that behavior.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/d61887d

Status: Fixed » Closed (fixed)

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

tonytheferg’s picture

Issue summary: View changes

rszrama, Is your patch from #17 still available on this? can't navigate to the link anymore.