Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Setup a product type with at least two product reference fields. Each reference represents a product in the bundle.
sometimes bundle can have 2/4/6/8 products inside. with actual funcionality, i have to add 8 references fields to make it work, right?
why to not allow to select multiple product using only one reference fields?
Comment | File | Size | Author |
---|---|---|---|
#40 | 1489548-39.patch | 14.62 KB | torgosPizza |
#28 | bundle_type_selection-1489548-28.patch | 7.45 KB | deggertsen |
#24 | single_product_reference-1489548-24.patch | 3.29 KB | deggertsen |
#7 | commerce_product_bundle.module.patch | 3.01 KB | bassam |
Comments
Comment #1
olafkarsten CreditAttribution: olafkarsten commentedNot really. You can select as many products per product reference field as you want. It is more a question of what make sense. You can only select one product per reference in the add to cart display. So you need at least two product reference fields. Otherwise you don't have a bundle and doesn't need the module at all.
Comment #2
dgastudio CreditAttribution: dgastudio commentedhm, u are right. thank u.
Comment #3
tbenice CreditAttribution: tbenice commentedActually for me this is still an issue, though maybe I just don't understand. We have bundles that can include any number of product skus, not just ones to choose between (ref field cardinality==unlimited), but actual separate products.
Example: we sell an 'all albums' bundle for a recording artist. Each year there's a new album added to the list...so, I have to add a new field to the product bundle. Unless I don't understand, this solution doesn't seem to scale well.
Comment #4
olafkarsten CreditAttribution: olafkarsten commentedHmm, not sure if I got it right. You have a product bundle existing of all albums of a specific artist? But that is plain commerce suite functionality. You don't need commerce product bundle at all. Just create a standard product display.
Comment #5
tbenice CreditAttribution: tbenice commented@olafkarsten thanks for the reply. Yes, but :
if I
1) create an album product with 1 reference field
2) add all album skus to the 1 reference field
then the user can select 1 and only 1 sku from the product page via the add to cart select form. I need them to be able to be given ALL skus for the product when purchasing the bundle. Does that make it more clear?
Comment #6
deggertsen CreditAttribution: deggertsen commentedThis still seems very unclear to me. I don't understand either of these statements:
Is this saying that if you only have one product reference field the customer is forced to choose between which of the products in that field are referenced? So you have to have a product reference field for each product in the bundle? I will have upwards of 10 products in a bundle sometimes.
My understanding is that commerce only has functionality to allow you to select from one product referenced in a product display, not a bundle of 10 products.
What I need is to be able to reference a bunch of products and have the add to cart button add all of them at a discounted price defined by the bundle.
I will play with this more and see if I can figure it out, but I feel like the documentation needs to be clarified. Or at least the need for multiple product reference fields...
Comment #7
bassam CreditAttribution: bassam commentedPlease find the attached patch.
It alters the module to have the following behavior:
You can now change the product reference field to "unlimited". This way, you can have one field to reference all the products.
In the old code, when you create the product display you will have to choose one item to add to the cart. I changed that to have multiple items.
All the items are selected by default.
I suggest that we disable the field all together and make the "add to cart" add the products directly.
Comment #8
Nick Robillard CreditAttribution: Nick Robillard commentedbassam i like where you're going with this. have you by chance coded your suggestion to disable the field and add all items directly?
Edit: Actually i asked that too soon. Can just hide the field with css.
Comment #9
bassam CreditAttribution: bassam commentedAs you mentioned, we can use CSS to hide the fieldsets.
I can work further on this next week. I will post the patch once I finish.
Comment #10
kevinquillen CreditAttribution: kevinquillen commentedWhat they are trying to explain is you should really only need one reference field that has unlimited cardinality - because ultimately you are creating a box with multiple product skus inside of it (bundle).
In the case of #3, they are saying that when you go to an artists page, one of the products on the page is their entire catalog. That 'Catalog' product references all the albums that artist put out - so putting that in your cart is really putting 15 albums in. You wouldn't want to have to create a field every single time to do this because its so varied, it needs to leverage cardinality.
I need this too - I will try the patch from #7.
Comment #11
tbenice CreditAttribution: tbenice commentedDoes the patch also need to include a new commerce_product_bundle_get_sub_items function? I bet there are a few other functions in there that assume separate fields.
Comment #12
ElCuervo CreditAttribution: ElCuervo commentedGreat Module.
As people are mentioning, this is the behavior we were expecting as well. We can't really anticipate/limit how many products people might add to the bundle.
I have downloaded the patch and will test it.
Great work!
Comment #13
Jordanmt CreditAttribution: Jordanmt commentedI've had success applying Bassam's patch in #7, so far it appears to work as advertised.
With respect to hiding the field, would it not be sufficient to change the form from a select input to a hidden input? I'm currently playing with the form as an item type, as I'm also looking to display the referenced products individually on the product bundle page.
Edit: Not having price being calculated in the patch, likely related to what tbenice brought up in #11.
Very excited about the activity on this thread.
Comment #14
ibuildit CreditAttribution: ibuildit commentedYeah the price is not calculated correctly. Great work otherwise!
Comment #15
ibuildit CreditAttribution: ibuildit commentedActually, it depends on how you render it in the display settings of the product type. I can get it to display the correct price with "Admin display" / (Rendered product) I'm sure there are other settings that work too
Comment #16
ridgek CreditAttribution: ridgek commentedIt sounds like this thread is headed towards functionality similar to how Commerce PADO works. Using Entity Reference fields as Commerce PADO does seems like it would solve the original poster's issue, and as I understand it, Product Reference fields are deprecated when Commerce 2.0 drops. I feel like these two modules are due to overlap soon.
Comment #17
zmove CreditAttribution: zmove commentedSubscribing to the thread and +1 for the possibility to add only one product reference field with unlimited value.
I understand the reason why the author chose to have multiple reference fields to handle that, for example a computer seller can create a product where the user can choose between different hard drives, different CPU etc.... to build their own config. So you have to create a "Hard drive" product reference field, "CPU" product reference field... add several products to each and the user will have the dropdown and can choose what he want for each component. The number of components is the same for all computers so you know how many product reference fields you have to create.
But that's not enought flexible for all use cases. Some guys in this thread, me included, just needs to sell several products with only one add to cart. For example a furniture seller that can sell a bed, a chair etc... but maybe want to sell a whole room. You don't need to have a configurator for each products that compose the room and you don't know the number of products that compose that room, so it's better for them to have only one product reference field with multiple value.
So both case can have a use, I would not replace one by the other. The module should detect if the product have one or several product reference field, if only one => that's the second case, if several => that's the first one.
Comment #18
deggertsen CreditAttribution: deggertsen commented@zmove. Thank you for your sound explanation of a use case for this module as it is currently.
I'm wondering if we need to create a separate module for this, or if this module could be adapted easily enough to support just one field?
Comment #19
ridgek CreditAttribution: ridgek commentedWell, so I tried Commerce PADO and it's good for being able to do a simple upsell by adding checkable products to an Add To Cart form, but it is not a "bundle". Commerce Product Bundle is good for selling a bundle of products on a product type when the bundles will have a set number of products. I think the customizable computer tower is a pretty great example for Product Bundle's strengths, but it seems we all have a totally different use case for our stores, and though I haven't tried bassam's patch, I'm not sure this is the right direction to be pushing this module, either.
Anyway, deggertsen, I think a separate module is in order, so I've been working on my own module that should help address some of the solutions posters in this thread are looking for. It relies on Relation module (which allows to define relationships between entities using separate entities) so that we can have really complex relationships for groups of products in a single Add to Cart form (but at the expense of way increased server load because of this). The idea is to be as flexible as possible for options to sell multiple products together in a bundle (I call it a "lot").
I'll need to have it ready to go by January but I'm hoping to have it ready sooner. Next update will be next week, I'd appreciate any help testing/coding. :)
https://drupal.org/sandbox/ridgekuhn/2099907
Comment #20
olafkarsten CreditAttribution: olafkarsten commentedThanks zmove for #17. Thats the point. It would be very rude to completly change the current behavior of the module. But extending the functionality is fine. Patches are welcome.
Comment #21
zmove CreditAttribution: zmove commentedI don't think a separate module is needed to handle that (or maybe it would complexify too much this one but I don't think so).
The thing to do is "just" to detect how much product reference field the product have.
- If one : We are in the second case, the "furniture" case (see #17)
- If several : We are in the first case, "the computer" case (see #17)
I don't understand what could explain that it's better to write another module, most of the code is already here and it's just a new condition to add with some minor behavior change. In addition it would make the module "intelligent", that could understand the use case. It would be more complex for the final user to create a new module ans say in the readme (please, install that module if you are in a furniture case, but please, create only one reference field or it will bug), (please, install this other module in a computer case, but please, create at least 2 reference fields or it will but).
We are on the bundle product module, we identified 2 different and viable way to handle bundle product, now this module should handle them all. (That's my opinion)
Comment #22
deggertsen CreditAttribution: deggertsen commentedIf that is the case, I certainly agree that it would be better to simply include it in this module. Maybe we just need to have checkbox or something that tells this module to recognize that a product reference field should bundle the referenced products instead of leave it as options to select. Maybe there is a better way to do this, but in any case I'm not much of a programmer so I probably wont be much help other than testing and debugging.
Comment #23
kevinquillen CreditAttribution: kevinquillen commentedA bigger reason to make the case to have one field either contain multiple references (cardinality) and make it editable (with maybe a Views list to pick from) to sub items in and out to customize for a customer is Views.
If you are doing a lot of metrics and reporting, having umpteen reference fields is quite the burden depending on the type of data mining and forecasting you are attempting to do. That means for X criteria, Y fields need to be added as filters, searched in a giant OR, etc... cumbersome. One field makes this much simpler.
Comment #24
deggertsen CreditAttribution: deggertsen commentedI've got a start. Definitely not functional, but I've added an option in the field formatter settings to "Bundle all referenced products in field". Checking this at this point will simply change the foreach statement in commerce_product_bundle_form_alter(). I need to figure out how to pull each product referenced in a single field. Once I've figured that out I might be able to have a working patch. If anybody has any ideas or suggestions, please share.
Thanks!
Comment #25
deggertsen CreditAttribution: deggertsen commentedOkay, looking over this more there is a lot more that will need to happen than I originally thought. A lot of work will have to be done in the commerce_product_bundle_add_to_cart_form() function, but at this point I'm not sure what. I probably wont get to work on this anymore until next week, so if anybody else wants to take a crack at it before then, please do! I'm still a noob when it comes to programming, so any help is appreciated!
Comment #26
kevinquillen CreditAttribution: kevinquillen commentedThe patch in #7 facilitates one field with unlimited values for referencing, but here are the current design issues (maybe stemming from #7) whether you use the multiple single field approach, or single field multiple value approach:
Really, the substitution functionality is the big one. Some use cases are people who need bundle products but also need to allow the customer to swap bundle products in and out based on what is being sold, without affecting the original bundle product itself.
Comment #27
deggertsen CreditAttribution: deggertsen commentedOkay, so I feel really dumb. I didn't even see the patch in #7. That will help a lot as I proceed with this. Thanks for pointing out those issues @kevinquillen.
Comment #28
deggertsen CreditAttribution: deggertsen commentedAlright, here is a working patch thanks to @bassam. I have added a setting in the display settings that allows you to "Defines how referenced products are handled." There are 3 available options here:
1. Single Select Box (This is what is the default now for the module)
2. Multiple Select Box (This is what patch #7 did by default)
3. Hidden, add all products
This last option will simply add all products referenced in a given field to the users cart and hide any select options (no need to use CSS).
While I have not thoroughly tested it, at first glance it appears to be working. Shipping is not being calculated based on the bundled products, though this may be by design. There is a function that supposedly "Adds the selected shipping information to a line item added via a line item manager widget", but shipping is not being calculated. I'm assuming that if I add shipping fields to my bundle product that shipping will then work just fine.
Some other things to note:
Please review! Thanks!
Comment #29
jonathan_hunt CreditAttribution: jonathan_hunt commentedI've applied the patch in #28 and have a bundled product with multiple SKUs in the first product reference field (PDF downloads via Commerce File 7.x-1.x). When I go to add the product to the cart, I get fatal PDO exception (see below). I'm unclear as to why saving a line item is transformed into saving a file into file_managed table...
Comment #30
deggertsen CreditAttribution: deggertsen commented@jonathan_hunt. What version of commerce_file are you using? It might have something to do with that module not playing well. I am also using commerce_file version 2.x but am not seeing this problem.
I'm also wondering if you have a file upload in any of your line item types?
Hard for me to say what the problem is.
Comment #31
jonathan_hunt CreditAttribution: jonathan_hunt commented@deggertsen: The site is using Commerce File 7.x-1.0. The products involved have the Commerce File field type but not other file-related fields (other than field_image - default product).
Are you using Commerce File Bundle, or just Commerce Product Bundle and Commerce File 7.x-2.x?
Comment #32
deggertsen CreditAttribution: deggertsen commentedI'm using Commerce Product Bundle with Commerce File 7.x-2.x, not Commerce File Bundle. Your problem must have something to do with commerce file 7.x-1.0 not working with Commerce Product Bundle...
Comment #33
deggertsen CreditAttribution: deggertsen commentedHas anybody had a chance to review the patch in #28? I would love to see it get committed. It's working great for me other than #2176379: Rules aren't firing for rules dependent on line item evaluation, but that's a separate issue.
Comment #34
torgosPizzaI'm trying to get your patch to work but it seems to be pretty inconsistent. I'd love it if you could write up a clear, step-by-step walkthrough, since the README is pretty hard to understand. And, it seems like changing some of the Cart form display settings ends up breaking things, causing product fields (and sometimes the cart button) to suddenly disappear, but I am still trying to figure out exactly how that's happening.
Additionally I think the module's approach is fundamentally flawed.I could be wrong but to me the most intuitive usage is to just say, "I want to create a product bundle display type that, instead of choosing one product from a dropdown, allows me to select one or more (or all) of the products referenced." This makes the most sense and I imagine would fit the scenario of 90% of use cases.
EDIT to say that I rethought this aspect, and now realize that it's the best route. Because for instance if we want to have a product display that shows both regular product cart buttons as well as a bundle cart button, this is the only way how, since the cart option is in a per-product type basis. This lets us do things like, for example, create a "Music Album" display type that can reference "song" products (with individual cart buttons) as well as "album products" (bundles that allow you to buy all the tracks in the album at one time).
Comment #35
torgosPizzaI took another stab at configuring and I did get things to work as expected. One caveat is that the "parent" product (the Bundle type that contains a reference field to bundled products) can't be licensable using Commerce License. Commerce License has a line_item_presave() hook that expects either $line_item->commerce_license to be empty, or a valid license, but using Commerce Product Bundle you get a $form array added to the line item.
I'm not sure offhand what the proper fix is, perhaps an #after_build function in the Commerce Product Bundle module that removes the parent product's license. Unless of course we can figure out how to make bundles work with licensable product types, but if not we may want to make a note that Licensable product types do not yet work with CPB.
Additionally, you need to turn the fieldset Off for your Add to Cart Bundle form field, in order to get the "Hidden" setting to fully work. A minor nitpick of course but if we can we should hide the entire fieldset/item if the Hidden option is selected.
This all being said, the patch does address the topic of the issue, and I'd say it's RTBC. I wouldn't mind someone taking the helm of this module because bundling products is a severely lacking feature of Drupal Commerce.
Comment #36
torgosPizzaCreated an issue for License compatibility here: #2505939: Commerce License support
Comment #37
kscheirerI'd like to commit the patch in #28 if its RTBC, can we get a second opinion?
Comment #38
deggertsen CreditAttribution: deggertsen commentedJust to add my voice here. I've been using the patch in #28 for a long time now on the production site and it has worked great. I'm all for committing it.
Comment #40
torgosPizzaHere is a bit of a re-roll on this patch to fix some whitespace issues. It's basically the exact same thing as the one in #28 but should be a bit more readable.
I'll be committing this one to 7.x-1.x.
Comment #41
torgosPizzaCommitted and pushed to 7.x-1.x. Thanks everyone!
Please continue to test and file any further issues if you are using the "single reference field" mode. Which, personally, I think everyone should because this is probably 90% of all use cases.