Bundles have quantity = 0 when they are added to cart.

cart1

This causes whole bundle to disappear when "Update cart" or "Chekout" button are pressed.

Also when I update the quantity on the bundle, it updates bundle items OK and main bundle gets wierd value. Eg. on next screenshot: I've set bundle quantity to 5 and updated the cart. ("2" is result after cart update)

cart2

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caschbre’s picture

FileSize
39.97 KB

I just wanted to add that I'm having a similar situation with bundle quantity and how bundles are represented in the cart.

On the bundle display product reference field I have the following disabled:
- Attempt to combine like products on the same line item in the cart.

My goal is that each product or product bundle is on it's own line. Basically removing the need for the quantity field. What I'm seeing however is that when a bundle is added twice, the products in the bundle are each on their own line, but still within the bundle. The bundle quantity is also incorrect.

commerce bundle cart

caschbre’s picture

Ok, I believe my issue (#1) is unrelated to the original post. So ignore #1 and I'll create a new issue.

tnfno’s picture

This bug makes the module unsuited for production right now, otherwise I think it is a great module.

If you for example have a bundle of 4 products and add it to the cart, the individual items are shown correctly in the cart, but the qty of the bundle defaults to 0. Update/or checkout will remove the bundle completely since it has 0 qty.

If you manually enter 1 as qty in the cart, update/checkout seems to work. But, if you enter 2 as bundle qty, instead of keeping the qty of each individual products and specify 2 bundles, it multiplies the qty of the individual items and resets the bundle qty to 1.

tnfno’s picture

After some more testing I have done a simple quick fix to make the module usable. The biggest problem is that since the default qty of the bundle is set to 0 for some reason, it is not possible to check out since clicking update or checkout will delete the item.

To avoid this, you can comment out line 115 in \commerce_bundle\includes\views\handlers\commerce_bundle_handler_field_edit_quantity.inc:

//$deleted_line_items[] = $line_item_id;

This will keep the items in the cart and enable checkout.

The final solution will probably require some modification to how the group / item quantities are shown. When you change the group qty the bundle items are multiplied and the group qty set to 1 (or 0 as a bug). if you manually enter 1 and update, the item qty are reset correctly, but I think it is confusing for the customers how they can change the number of items.

caschbre’s picture

@tnfno... I'm not experiencing the 0 quantity issue. Right now I have to products in my bundle, both at 1 qty each. My bundle is showing as qty of 1 in the cart so it's working as expected for me.

Can you elaborate more on your product and bundle setup?

deggertsen’s picture

I am having the same issue here. I add a bundle to my cart and when I go to the cart the quantity is shown as 0 for the bundle. This causes the cart to be empty when you try to proceed to checkout or update your cart. I can't figure out how my setup could be wrong. Everything is exactly the same as it is stated on https://www.drupal.org/node/2182973, except for where you manage the bundle display. On that page I have two extra options currently set to "Total Bundle Price Label: Total Set Price" and "Product view mode: commerce_bundle_add_to_cart_form".

@caschbre, is there any information specifically that would be helpful in trying to debug this issue?

admurray’s picture

I am having the same issue, and bundles are set up correctly according to documentation.

To replicate:

1) I add a bundle to my cart, and proceed immediately to checkout. Only the bundle line items are seen on the checkout pane. There is no reference to the bundle, but I can checkout with the line items as is.

2) I add a bundle to my cart, and go to the cart pane. The bundle is referenced, and shows 0. This prevents me from proceeding through checkout, and quantity itself can not be altered from 0.

deggertsen’s picture

@admurray, I never got this fixed. Let me know if you're able to figure anything out...

mrbrns’s picture

Hi, I think basically it's the same issue as here so as I wrote there I think the error is in the table or something like that, because the query of $order_qty_sum makes a sum of all the rows of the field_data_commerce_bundle_config_id that have the same commerce_bundle_config_id_value, and the problem is that all bundles receive the same id.

Let's say that two users buy the same bundle that contains 4 different products, the query will count that sum as 8 so you will have that $form_data['#default_value'] = round($order_qty_sum/$unit_qty_sum); will be 4/8 giving you a 0.5 result getting rounded to 0.

I hope I made myself clear, I will try to search for a solution for this but since I'm not a programmer it might take a while so any help would be appreciated.

deggertsen’s picture

Proposed solution in #2351397: Quantity edit handler error on shopping cart view after adding a bundle product

changing commerce_bundle/includes/views/handlers/commerce_bundle_handler_field_edit_quantity.inc on line 48
$order_qty_sum = db_query("SELECT SUM(quantity) FROM commerce_line_item cli ...
to
$order_qty_sum = db_query("SELECT SUM(quantity) FROM {commerce_line_item} cli ...

admurray’s picture

@deggertsen - I'll check that out and get back to you. Is that something that would go in as a patch so I don't have to hack contrib?

Thanks!

deggertsen’s picture

@admurray. Yeah, it would need to be a patch. I hope to be testing this soon and if I do I will create a patch myself.

admurray’s picture

I just tested this locally, and the fix does work. I am attaching the patch with the code from #10.

admurray’s picture

Status: Active » Needs review
deggertsen’s picture

@admurray, do you have any other patches applied to dev? When I downloaded the dev version of the module and applied the patch it did apply cleanly, but it didn't seem to work on my site. Cleared caches and everything, but the quantity is still 0 when added to my cart. It also was only showing the first of the products contained in the bundle.

admurray’s picture

Hmmm...no just that one. I can try and test across a couple of sites to confirm.

UPDATE : I have tested this on multiple sites, and cart quantity consistently shows correct amount.

deggertsen’s picture

Perhaps I need to reinstall? I'll try that when I have more time.

tnfno’s picture

The patch from #13 seems to solve the issue of erratic adding/substracting products when changing the bundle qty. But the problem with the 0 qty shoing initially still remains on my site with latest Commerce Kickstart. This means that updating the cart removes the bundle, unless you override the 0 to the correct qty.

Will try to find out where it gets the 0 from, temporary fix is to comment out the line that removes the bundle when the qty is 0, see post #4. Then it will still sho 0 as bundle qty, but keep the correct qty through cart updates and with patch #13 you can change bundle qty correctly.

admurray’s picture

When I try #4, I lose the ability to continue to checkout, and line items are not updated as described.

admurray’s picture

Ok, so I discovered a couple of issues digging in further -

1) line 55 $form_data['default_value'] was using round() without specifying a mode to round up or down. I replaced this with ceil() since the value being returned initially was a fraction and I wanted it rounded up to 1.

2) The default value as is would always return 1, as $order_qty_sum/$unit_qty_sum is always a fraction. To remedy that, I kept $order_qty_sum and divided it by the actual number of line items in the bundle. This returns a correct purchase quantity upon cart update.

I am submitting the following patch for consideration.

Thanks!

nedjo’s picture

Two queries are used to calculate the quantity, producing the results $unit_qty_sum and $order_qty_sum.

The bug results from the fact that the second query limits results to the current order while the first one does not.

Attached patch fixes this issue by adding an additional join and associated WHERE condition to restrict the first query results to the current order.

Other incidental changes:

  • For consistency with Drupal core conventions, use the full form INNER JOIN rather than the short form JOIN.
  • Fix two curly bracket errors (one set of missing brackets, one misplaced bracket).

I have not retained the change from round() to ceil() from the previous patch. It seems like a plausible improvement but I'm not sure that it's required to fix the bug.

nedjo’s picture

eiriksm’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #22 does the trick for me.

Neo13’s picture

I can confirm that the patch is working.

tonytheferg’s picture

#22 worked for me!

mlee11111’s picture

Looks like this is related to recent changes in database.inc (@see https://www.drupal.org/project/drupal/issues/1713332).

commerce_bundle-cart-quantity-zero-2200149-21.patch places cid alias inside the table prefix braces which up until this database change, seemed to work:
{field_data_commerce_bundle_config_id cid}

In case anyone gets the error 'Base table or view not found...', I repatched with cid outside the braces

mlee11111’s picture