Hi!
I need my lists of products and my product display for a clothing shop show the message "Available in X colors" for each product. Each color corresponds to a product variation. I thought I had it. I was just counting the number of variations that are associated with each product display through the multi-valued field field_product. I do this in the views that display lists of products and in the product page (through a Viewfield field).
However, this is not fully correct. When some of the product variations for a product display are disabled, the "Available in X colors" still displays the total number of product variations associated with the node, and not only the enabled ones. I'm trying to modify my views so that the disabled product variations are filtered out but I can't find out how to use the product variation state as a filtering criterium. Using a relationship connecting Product Displays to Products doesn't seem to work because the field_product field is multi-valued and the relationship will only take the first product variation in the list.
This doesn't seem to be an unusual feature. Has anyone done this before?
Thanks in advance for your help!
David
Comments
Comment #1
dpico commentedComment #2
dpico commentedI forgot to say that I have a solution for a display page. I can use a view that lists all active product variations for the corresponding product display, by getting the Nid from the URL.
The problem comes when I need to display the "Available in X colors" message for all the product displays that are listed by some view. The view that calculates X should be executed once per product display in that list. I don't know how to do that (not to talk about making it efficient.)
Comment #3
rszrama commentedI haven't tried it, but you can always look at using some sort of Views field on the node to show that. I know there are a couple modules that offer that functionality, can't remember the currently recommended one. As for making it efficient... I think you're just going to have to use the Views cache and figure out if it can invalidate when the node / product is updated (or make it do so yourself) or if it just needs to be on a timer.
Comment #4
dpico commentedThanks Ryan! I'll try with Views Field View and see what happens. I'll report about it here for future users.
Comment #5
rszrama commentedThanks. : )
Comment #6
dpico commentedIt took a while, but I did it. I used the Views Field View module. The main view with products includes a views field that send the display node id to another view that calculates the number of active variations. Sending the node ID as the argument for the nested view was a bit tricky but it worked well eventually.