I have need of using commerce product bundle to offer a more simple grouping of products than is currently available via the configuration. I essentially just need to be able to add the bundle in a single add to cart click which creates the bundle line item and all of the sub product line items. To achieve this I have added in the attached patch another cart configuration setting.
If the "Bundle as simple group" setting is enabled essentially all of the more interesting features of the add to cart form are disabled and the bundle with all of the associative products (as sub line items) are added to the cart in one click.

Comments

olafkarsten’s picture

Status: Active » Needs work

Okay, first of all - thanks for the work. At least I will test the patch - IF ...
I know the module code is not really in good shape (intendation, comments, ... such things). But we shouldn't make it worse. Your Patch is really bad formatted. It contains dozen of dozens lines of code that doesn't change anything. Often, simply the format is changed (intendation/whitespace), not to it's best. That makes it hard to read and follow the real code changes.

Please use a actual dev version of the code, put in your changes - and only them. Don't copy and paste, move around any other code and create the patch again. Then we will test it. Please don't be disappointed and do not give up now. This is not personal. We appreciate your work.

olafkarsten’s picture

@@ -293,83 +300,94 @@ function commerce_product_bundle_add_to_cart_form(&$form, &$form_state, $parent_
   $attribute_names = array();
   $unchanged_attributes = array();
   
-    
-  foreach ($products as $product_id => $product) {
+  if($settings['bundle_as_simple_group'])
+  {
+    foreach ($form_state['bundle_products']["{$parent_product_id}__field_bundle_courses"] as $subProduct) {
+      //$form_state['values']['bundle'][$subProduct->product_id]['product_id'] = $subProduct->product_id;
+      $form['bundle'][$subProduct->product_id]['product_id'] = array(
+          '#type' => 'hidden',
+          '#value' => $subProduct->product_id,
+        );
+    }
+  }

I've tried to guess what the patch should do. I stumbled here - __field_bundle_courses ?? - I guess this snippet is left from your specific use case?

I read your initial post again, and I doubt whether I understand your point. The bundle module is all about "one add to cart click" for all the subproducts in the bundle. So I don't really get it. Can you help me with that?

Smoocher’s picture

same problem!
You have any solution?

ASupinski’s picture

StatusFileSize
new3.14 KB

Sorry for the delay in my response, I wasn't online this weekend. As you have found I added the block of code you have indicated above above and put a lot of your existing code into an else block (thus changing the indentation on all of it). The purpose of this block is that it prepares the FormState on submission of this form to work with your existing submit handler and actually add all of the sub line items at once (the first foreach in commerce_product_bundle_add_to_cart_form_submit doesn't care what the id is so I just used the product_id). The only other real changes were to add the new field formatter setting and a small block of code that I added into both commerce_product_bundle_add_to_cart and commerce_product_bundle_update_cart to default to using the passed in quantity when the sub line items quantity is not specified.
I had thought I had the formatting correct earlier but here is my second attempt.

olafkarsten’s picture

Nice, this one is better. Thanks! And delay? Hey, its weekend and we have to live? Congrat for a offline weekend!!!

But now have a closer look. The patch contains a part for commerce_product_bundle.rules_defaults.inc. Did you see it? It doesn't change anything. So we have to remove it from this patch. The first part now is much better readable. So I see you want to change the display formatter settings. It's fine, but that's all. After applying this patch, we will have a setting in the display formatter. But this setting actually changes nothing. The patch lacks the corresponding change in the add to cart form. (Maybe Validation/Submit functions?)

I'm afraid we need another one. And BTW, it is okay to change intendation of bigger code blocks if you insert a loop or something. But there shouldn't be tens of ... removing/add of empty rows oder removing/adding identical blocks of codes. This results in +/- lines and code blocks that change nothing, but make the patch unreadable. Compare your both patches and you will see what I mean.

ASupinski’s picture

StatusFileSize
new3.33 KB

Ok, I think that I have this one cleaned up, I'm not sure how I managed to lose a bunch of my changes on the last one but third times the charm. I manually removed the indentation changes from my file to make the patch more readable... there has to be a better way, isn't there?
Thanks for your patience.

olafkarsten’s picture

["{$parent_product_id}__field_bundle_courses"] this wouldn't work in general, right? You can use $id here, as we even build that in the form function some lines above.

As a result a I got an add to cart form with some empty fieldsets - without the products. I'm not sure how it should look. Did you have a screenshot of you product display?

BTW: You really should test your patches on a clean install before posting in the issue queue. Otherwise it can easily happen that such "specific" code slips through. I know it costs some time, but for now its mine ;)

ASupinski’s picture

That syntax should work just fine, see http://www.php.net/manual/en/language.types.string.php#language.types.st... under "Complex (curly) syntax"

The result should be a very simple add to cart form with no displayed drop down of products that adds all of the products in the bundle to the cart (as sub_line_items) on submission.

Sorry if I left any issues.

olafkarsten’s picture

__field_bundle_courses it is more that part, I guess courses are your specific bundle. :)

ASupinski’s picture

StatusFileSize
new3.29 KB

Wow I took that the wrong way! Sorry I seem to be a victim of my own automation, I can have a replica of my site running locally easily but getting a clean Drupal install for testing pure Module updates seems to need some work on my system (really I just need to get better at Simpletest) Anyway I hope this is the last of my stupid mistakes!

essbee’s picture

I'm a big fan of this patch.

Makes for a very simple bundle that will handle a lot of site's basic requirements - that is bundling a number of unique products together into the cart.

One thing to note, is that you need to have "Display the options in a fieldset." disabled otherwise you end up with an erroneous fieldset. Might be worth checking for this in the fwidget form, disabling the checkbox when the Simple Group is selected.

I'll post any further things I see in testing with this patch implemented.

olafkarsten’s picture

Okay, I does a test and I'm sure this patch isn't something I would check in, before some substantial testing. Beside the problem in #11 I've noted some others. If you put more than one reference field in the bundle product type and use different settings, you didn't get a working add to cart form anymore - the calculation rules seems broken, the form looks not useful anymore ...

If we want a simple variant like this, than we have to make sure that it works with all possible combinations of settings OR we have to prevent, that a user can choose settings that breaks the site.

essbee’s picture

Status: Needs work » Needs review
StatusFileSize
new24.96 KB

Patch rerolled against latest (Jan 6th) dev .

I also fixed the indentation on the if statement. This makes the patch much longer purely because of the huge block requiring indentation.

olafkarsten’s picture

Status: Needs review » Needs work

Thanks essbee for your work.

The patch needs some work before we can consider it.

1) we have the issue, essbee mentioned in #11
2) If you have more than one product reference field in the bundle, and not all reference fields use the "simple grouping", the add to cart form crashes.
3) If you have more than one product reference field, all of them using "simple grouping", I get different prices in the add to cart form and the cart.

I have stopped than ...

mediapal’s picture

Is the SimpleGroupBundle working with commerce file ?

olafkarsten’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing. No development for D7 anymore.