How can I show the products that are within my product kits in a view?

Im using a view for the taxonomy term override. This is working great for all my products. For my product kits however only the name if the kit is being displayed and I cant see any fields for the contained products. Do I need to use a relationship? Or is their an ubercart admin setting that makes these fields available?

Thanks

Comments

jdln’s picture

Anyone? Surely im not the first person to need this functionality?

jdln’s picture

Ive tried using display suite to create a build mode for my view but it doesn't seem to have access to the necessary fields.

The closest it has is the Product: SKU. The product SKU of a a kit contains the SKUs of its contense but this isn't exactly the same as the node title of the products.

jdln’s picture

Ive got some of the way with content templates, but I cant get all the information I need.

longwave’s picture

Category: support » feature

This is not supported at present, it needs someone to write the Views integration code.

Anonymous’s picture

I need this too. I'll post here if I find a good idea ^^

cafuego’s picture

Version: 6.x-2.3 » 6.x-2.4
Status: Active » Needs review
StatusFileSize
new8.14 KB

Here is my first attempt at some views integration for product kits. The attached patch applies to UC 2.4

It contains two boolean node filters:

  • Is a product kit
  • Is part of a product kit

The latter is managed by a sub-select query, which is ugly. It should be using an INNER JOIN, but I don't know how to define one of those in a filter handler :-)

It also defines the uc_product_kits table and some views info for that, so you can add a relationship and display product kit information on node listings.

I'm not particularly proficient with views code, so I may have stuffed up the latter part. It seems to do what I need it to do, though. See how you go with it...

Status: Needs review » Needs work

The last submitted patch, 873398-views-integration.patch, failed testing.

cafuego’s picture

Status: Needs work » Needs review

I'm not convinced my patch makes that test fail.

tr’s picture

Version: 6.x-2.4 » 6.x-2.x-dev

Oooo, the testbot's getting better! It can now successfully run on fixed-point releases. But that's not what you wanted to do, especially here, since 6.x-2.4 is pretty old and was released before we did the PHP notice cleanup. Changing version to 6.x-2.x-dev to see what happens.

I installed the patch and ran the tests locally, and they all succeeded. Patch looks good to me except for some minor documentation comment problems ("Implementation of" should be "Implements", etc.). I haven't tried it out with Views yet.

This should be ported to D7 after it goes into D6.

tr’s picture

#6: 873398-views-integration.patch queued for re-testing.

cafuego’s picture

StatusFileSize
new8.9 KB

Attached patch done against 6.x-2.x branch and with updated comments.

tr’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Committed to 6.x-2.x. Thank you.

Needs to be ported to 7.x-3.x now.

dags’s picture

Thanks for this.

tr’s picture

Component: Module integration » Product kits

Moving to "Product kit" component.

Anonymous’s picture

Hello,
Can I display the name of the products contained in the kit and their images with this patch ?
Do I have to set a relation in views or anything else ?

Thank you very much.

Island Usurper’s picture

Status: Patch (to be ported) » Needs review

This confused me for a little while. Since product kits are nodes, I expected {uc_product_kits} to be joined on {uc_products}.nid = {uc_product_kits}.nid. Since it was actually joining to the product_id, a list of nodes would only show you which ones were part of a product kit. I would think that we would want a list of kits that knew which products they contained. Once I changed that, I realized it should actually join on the vids of both tables to prevent duplicates when revisions are used.

This file is actually several commits. Apply with git am <filename>.

Island Usurper’s picture

StatusFileSize
new13.34 KB

This file, that is.

bancarddata’s picture

Pardon my ignorance, but can you please tell me what I should now see after applying the patch in #17? I am trying to take control of my product kit pages with views. My main goal is to be able to add tooltips for the kit parts that show the description and image of each component in a little popup for each part. I had seen a way to do this with Views and the Beauty Tips module, but obviously I need to be able to get my kit pages as a view first. I believe this patch is intended on providing this capability but I can't see what changed in Views after this patch was implemented. Thanks for your guidance!

Anonymous’s picture

If I remember correctly what I've done to make a product kit view... I think you have to set a relationship (there should be two kinds of product kit relationships) and then find the fields you want. Maybe I'll post an export of my view if you need it.

bancarddata’s picture

I think a screenshot would be most helpful if you can post one. Thanks! I am not sure what kind of relationship you are referring to. I was able to easily make a list of kits, and show them one per page, but that didn't really do me much good.

Anonymous’s picture

StatusFileSize
new111.99 KB

Screenshot... but in french, sorry...

longwave’s picture

StatusFileSize
new17.21 KB

This patch changes the joins and relationships, so the joins are no longer implicit, but you can add both kit parent and kit component relationships, and then access any parent or component field via that relationship.

The "is kit" and "is kit item" filters don't seem to work, but you can use "Require this relationship" when creating relationships to effectively do the same thing for many use cases.

Status: Needs review » Needs work

The last submitted patch, 873398-product-kit-views.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

#22: 873398-product-kit-views.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 873398-product-kit-views.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

#22: 873398-product-kit-views.patch queued for re-testing.

jpdaut’s picture

This works very well already, however I would like the View to show options' images from the attributes options of the kit components. Do you have suggestions on how to proceed?

Thank you.

longwave’s picture

Attributes and options are not yet available in Views; that should go in a separate feature request.

When you say "this works very well" are you referring to the patch in #22 or something else?

jpdaut’s picture

StatusFileSize
new47.07 KB

I'm referring to patch #17, sorry. I will test #22 asap.

With #17 I have a working product kit View using both kit parent and kit component relationships, see attached snapshot.

It shows the attributes and the default options, however this is not interactive. What's needed is to be able to select options, and see option images dynamically as per uc_option_image.

I just created an issue for this as you suggested, drupal.org/node/1305722

uc_option_image is not integrated with Views, so that's an additional task.

If you add a field to the View: Product: Add to cart form / do not use a relationship, you do get the option widget, but not the option image. You also get the add-to-cart button which you don't want.

What I'm trying to do is actually more basic and outside of Views: I'm trying to just add option images to the regular product kit page, which already has the attribute/option widget, but not the images. Do you have suggestions on how to go about that? It would be very appreciated thank you.

longwave’s picture

I think what you're describing there is a fundamental bug in uc_option_image that will be easier to fix directly in that module than try to recreate via Views. I don't think it's currently possible to build a view that has multiple products listed but only a single Add to cart button for all the products.

jpdaut’s picture

I agree... I'm trying to add this functionality thru a hook_uc_form_alter implementation in a custom module.

I also opened a feature request with the uc_option_image here

loparr’s picture

Version: 7.x-3.x-dev » 6.x-2.4

I have the same problem with with drupal 6. Is it possible to make patch for drupal 6 as well? Thank you.

tr’s picture

Version: 6.x-2.4 » 7.x-3.x-dev

This will go into 7.x-3.x first, then be backported if possible.

loparr’s picture

Doe's this patch work for ubercart 6 2.4 as well?

cafuego’s picture

I wrote it for 6.x to begin with, as I don't use 7. See comment #11.

tr’s picture

Oh yeah, it's already fixed in D6!

longwave’s picture

Status: Needs review » Fixed

Committed #22.

loparr’s picture

Version: 7.x-3.x-dev » 6.x-2.7

Thank you for answer. Has this patch been added into the 6 x 2.7 or I have to use the patch from #11 ?
I still use uc 6x 2.6.

Thank yo very much.

longwave’s picture

Version: 6.x-2.7 » 7.x-3.x-dev

TR said in #36 it was already fixed in 6.x. It was first included in the 6.x-2.6 release. You said in #34 that you are still using 2.4 (which doesn't have this feature) but then in #38 that you are using 2.6.

loparr’s picture

Version: 7.x-3.x-dev » 6.x-2.6
Category: feature » support

My apologies, I looked at my modules page and found out that I use 2.6. Sorry for that.

What I am trying to achieve is to show both products (I created a product kit containing 2 products) using views. I followed the screenshots but with no result.
As a relationship I choose
Product Kit: Node ID
Product Kit: Product
I the field i choose Product Kit: Product and use relationship to kit.
Is this the correct way of achieving it?
Thank you very much for time and help

loparr’s picture

anybody can help me out with this?

FranckV’s picture

I am not sure it has been invoked here but there is an alternative way of displaying the products of a product kit in views : using PHP code.
My way of doing is a pretty good compromise :
- it does not use too much PHP (just for the "glue")
- it allows to use a standard view for the product kits display
- and another view for the product display (used as a subview with the product node nid as first argument)
- you don't need to wait for a patch
- it is adaptable to any existing Ubercart store

Basically, I add to the product kit view a new field : Global > Views PHP field (requires module Views PHP http://drupal.org/project/views_php or Views Custom Field http://drupal.org/project/views_customfield) that contains the PHP code that makes the link between the current product kit and its products.

The PHP code first gets the node nid of each sub-product of the currently viewed product kit. Then is uses views_embed_view() to insert the product details view using the node nid of the sub-product as argument.

Here is my sample code for reference :
The main product kit view is any view displaying product kits.
The subview has a machine name : 'my_uc_product_kits_subview' and view display name 'default'

<?php
//print_r($data,false); // for debug : checking available data
$znid = $data->nid;
$zvid = $data->node_vid;
$query = db_query("SELECT * FROM {uc_product_kits} WHERE nid = %d AND vid=%d",$znid, $zvid);
while($result = db_fetch_array($query))
{
  $subv = views_embed_view('my_uc_product_kits_subview','default',$result[product_id]);
  print $subv;
};
?>
loparr’s picture

Is it possible to do this without using php code?

Status: Fixed » Closed (fixed)

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

pareen’s picture

Hi loparr, did you find the answer?

Anyone, is this possible without php code?

loparr’s picture

Hi,
It depends what you want to achieve. If you only want to display product-kit page using views - that is easy.
Create new node view, filter nodes by type - product kit, add an default argument - node nid and lastly add fields - node title and so on
My scenario was to display product kit with all products details on a product page. That was little bit complicated:)

pareen’s picture

Thanks for the reply.

What I am trying to do is create a view which has all the individual products and display it on product kit page.

So if we have Product Kit 1, below it there will be a block (view) which will say this product kit has Product x | Price x | Add to Cart, Product y | Price y | Add to Cart, etc.

loparr’s picture

Hi,
So you want to be able to add to cart individual products from product kit page? That is interesting, I thought that the beauty of product kits was to add the products to cart together actually:)
I tried many ways to display individual products details using relationships in views but I couldn't manage to pull the data I wanted. What I ended up with was to create cck node relationship (drupal6) on product kit. Using this relationship allows you to pull all data from individual nodes.

end user’s picture

I've done that before as a test with D6/UC2 with regular products instead of product kit. I wanted to see if I could get away without using Attributes With a custom node-product.tpl.php, relationship module and views I removed the add to cart form and inserted a view. Using relationships I selected the related nodes to the main node. Then with a new region in the node template I inserted the view block which listed all related products in a table with a title and buy button.

So I set up one main product and three other product of the same kind but different bottle sizes.

1L
4L
10L
24L

Then with views I listed those on the 1L product page and unpublished the others so they wouldn't show in the catalog. It was just a test but can be done.