Tags/topics: 
4
Answers
Vote up!
0
Vote down!

Sub product dropdown uder parent products on the cart page

I am looking for a way to create sub products that will show as a dropdown list after a product parent has been added to the cart.

So there will be parent product and child products. Child products only show in the cart after a parent product has been added and you can add a child product directly on the cart page.

I will like to know what is the best way to implement a parent child system and relationship and have the ability to add child product directly to the cart on the cart page

The child product will be a drop down and will show directly under the parent product in the cart display

Asked by: docans
on March 6, 2014

Comments

I have been able to create related product using entity or node reference and relate a parent product to the child product. You can refer to https://drupal.org/node/1465920 for further info.

Now my problem is how to configure views to show the sub product under the parent product in the commerce cart page. So the user can see which sub product belongs to which parent.

Example

---Main Product 1 ---------------Price--Quantity---Total
------Available Sub Products
--------Sub product 1 -----------Price--Quantity---[ADD TO CART]
--------Sub product 2 -----------Price--Quantity---[ADD TO CART]
--------Sub product 3 -----------Price--Quantity---[ADD TO CART]

---Main Product 2 ---------------Price--Quantity---Total
------Available Sub Products
--------Sub product 1.2 -----------Price--Quantity---[ADD TO CART]
--------Sub product 2.2 -----------Price--Quantity---[ADD TO CART]
--------Sub product 3.2 -----------Price--Quantity---[ADD TO CART]

And after the product has been added to the cart the view table looks like this

---Main Product 1 ---------------Price--Quantity---Total
------Available Sub Products
--------Sub product 1-----------Price--Quantity---[UPDATE]
--------Sub product 2-----------Price--Quantity---[UPDATE]
--------Sub product 3-----------Price--Quantity---[UPDATE]

---Main Product 2 ---------------Price--Quantity---Total
------Available Sub Products
--------Sub product 1.2-----------Price--Quantity---[UPDATE]
--------Sub product 2.2-----------Price--Quantity---[UPDATE]
--------Sub product 3.2-----------Price--Quantity---[UPDATE]

How do i implement such a display in views. Thanks

- docans on March 17, 2014

4 Answers

Vote up!
0
Vote down!

Both views are possible. I think, though, it will take some thought and ingenuity to make this happen cleanly. First, we would need to create a Views table that can add "details" as a secondary row.

https://drupal.org/project/views_secondary_row

Next, you would want to be sure you're only showing the "parent" line items in your order. So you would want a filter that will weed out all "sub products." Usually helpful if sub products are a certain line item type or have a certain flag (checkbox field that gets checked when creating products?) on the referenced product to denote those types of line items that will be displayed in the secondary row.

Next we would need to add an embedded view to this secondary row (comes in Views 3 as a global option).

Next, we assume you have created your products in such a way it's easy to go from one product to a list of sub products. An easy way to do this is to add an entity reference field to products called "sub products" and then create a relationship based on the reference field.

The "embedded view" would take a product_id as an argument and spit out all the product displays (not the products themselves) from the relationship we mentioned above.

The next trick is to spit out either an "Add to Cart" form or an "update quantity" form. Add to cart should be easy. Just add the appropriate field for the add to cart.

From here, I'm not sure how we would continue. You see, the quantity update is a Views form element and I'm not exactly sure we could make it work with an embedded view. But lets assume that it's entirely possible (needs testing, possibly a simple custom views field), we would add a "quantity" field that interacts with the original cart's views form. Now we have BOTH an add to cart form and a quantity form.

Again, I would have to get to this point and explore how we might show only one or the other. Since the quantity is a line item field and the cart form is a node field, I'd probably hide the cart form and set the line item field to show the cart form [shortcode] when that field is "empty" (because there is no line item).

This is a tricky problem and would probably have many "head scratcher" moments. Have you considered hiring Commerce Guys to help you finalize this one part of your requirements? We do hourly chunks :D

http://commerceguys.com/quote

You can link to this answer to help us with an estimate.

Josh Miller
Answer by: Josh Miller
Posted: Mar 18, 2014
Vote up!
0
Vote down!

Thanks Josh. Here in a summery is what i have done so far

Section I
1. My main product has a product variation type of Computer
2. My sub product have a product variation of accessories
3. My main product has an entity reference field that references the accessories
4. I reference my accessories in the product variation so the [related product] field which is the entity reference is located at www.mysite/admin/commerce/config/product-variation-types/computers/fields

Section II
In the commerce cart view
1. I have a table display with columns |Product Name|Price|Quantity|Total|Remove|
2. I filtered for only the main products[computers] by adding the "Commerce Product:Type" filter to only filter for product of the "Computer" Type.
3. In the [Relationship] section of the view i added the "Commerce Line item:Referenced Products" in order to display the custom fields in the product variation as i could not find any other way call the image field in the view [Field] section. I even need to use product display fields but just don't know how to do them now.

Section III (per your recommendation this is what i have done so far)
1. I have download the views_secondary_row module and installed it.
2. I have create the Accessories view that will have to be embedded in the secondary row and it has the following option
a. View type = Commerce Product , View display = content-pane
b. which is on its own a table showing |accessories|Price|Quantity|Add to cart|

Question
1. What relationship do i have to create in order do a reverse call of the product variation so i can use the product variation id as the contextual filter and output the related accessories.

I have looked through the relatioship list and there is nothing that allows me to call the node variation as it relate to the field [Related product]. Do i have to change my view type?

Thanks

Answer by: docans
Posted: Mar 18, 2014
Vote up!
0
Vote down!

I have requested a quote and i still have not received any reply on my support. Please respond to me as soon as possible.

Thanks

Answer by: docans
Posted: Mar 18, 2014
Vote up!
0
Vote down!

I have found a possible solution using the commerce product add on module. It get me close where after creating the add-on products , the commerce cart view displays the add-on product directly under the main product.

How ever it also shows the addon product on the product page's cart form. I need the add on product(accessories) to only show in the cart after a user has selected a main product

Please refer to this link for further info https://drupal.org/node/2221595

Answer by: docans
Posted: Mar 19, 2014