Steps to reproduce:

1. Create several products (at least 2, I'd suggest 3)

2. Create a Product Kit

3. Add at least 2 (I'd suggest 3) products in your Product Kit

4. Now add this Product Kit to your cart

5. Go back to your Product Kit page & edit it

6. Remove one of the products

7. Save

At that point the cart was NOT updated. I usually get this error:

warning: Division by zero in .../sites/all/modules/ubercart/uc_product_kit/uc_product_kit.module on line 1090.

although not always. I'm not too sure what that is, but the real problem is not the division anyway...

At that point, I cannot get rid of the one product that was removed from the kit (from the UI that is.) It will stick to the cart and be invisible. That being said, it looks like I would not purchase it (i.e. the total looks correct without that item) but it is not unlikely that many other issues will ensue because of this! (i.e. If I remove the kit from my cart, I can still go to the Check Out page even though I have "nothing" in the cart and the total says $0.00. The reality is it is not exactly empty...)

I probably will not too often do something like this, but this is not a reason to not have valid code! All the people who put a kit in their cart should get their cart checked out to make sure that changes to the kit are reflected in there. I will be updating my kits all the time so they need to work right! 8-)

I may have a look later to see if I can find a fix, but I'm really not familiar with that code. If you have a good idea, let me know.

Thank you.
Alexis Wilke

CommentFileSizeAuthor
#12 620844-uc_product_kit-update-cart.patch682 byteslongwave

Comments

Syph’s picture

I am hiving this issue, did you ever resolve it?

AlexisWilke’s picture

Syph,

I've not been deleting products for a while... 8-}

But I'm pretty sure the bug is still there.

Alexis

ahimsauzi’s picture

Make sure that on your product kit you have a value greater than zero for the discount amount.

Not sure if that is a bug but when entering decimals in a form drupal or the discount mechanism reset value to 0.00 after saving.

AlexisWilke’s picture

ahimsauzi,

And what does that have to do with deleting a product part of a kit and in your cart?

Thank you.
Alexis

Cablestein’s picture

Version: 6.x-2.x-dev » 6.x-2.4
Issue tags: +edit, +content, +Ubercart, +update, +product, +Component, +item, +cart, +kit, +quantity

Jan 25 - 2011
Drupal 6.20, Ubercart 2.4

I have encountered this bug multiple times this week, both with my administrator account and a fresh test account, using fresh test product kits.

Overall, the main thing that seems to be happening is if you EDIT A KIT and ADD A COMPONENT to a kit, but the kit already exists in any users' cart, this is when all the problems seem to happen. The next time that user views or updates their cart, they will see varied combination of effects, like:

---Frequently happens: A red error message will appear on top of the cart page, always having to do with "Division by zero" in uc_product_kit.module around line 1113 or so --- OR --- "warning: Invalid argument supplied for foreach()" in uc_cart.module around line 1599.

---Frequently happens: Cart is completely blank. Upon clicking 'update', they will get the red error message stated above.

---Frequently happens: Cart total in cart block says something, but when viewing the cart page, the total is empty or a lot less. To put it a different way, it's like ghost products exist in your cart and you can't see them.

---Maybe happens frequently but haven't paid attention to it: For the products/kit components that are still viewable in the cart... the quantity shown will be something crazy like "0.77688" or "56.3455", or sometimes the quantity field will be completely blank.

We've tried messing around with kit component quantities, and other stuff... but have only been able to make the error happen when ADDING a component to a pre-existing kit which happens to be in someone's cart at the time of editing.

If you go back to the kit edit page, and take away that recently added component, the cart returns to normal (upon clicking Update Cart of course).

I hope this gets fixed!!

In the main time here is what we used to clear the errored cart:

 // Clear cart command, where "1" is user id
uc_cart_empty(1); 

This blows away the cart contents, errored or otherwise. Obviously not a solution, but maybe a helper to someone reading this.

longwave’s picture

Title: Product Kit in cart & Removal of Product » Division by zero after editing product kits that are already in the cart
Priority: Critical » Major
Issue tags: -edit, -content, -Ubercart, -update, -product, -Component, -item, -cart, -kit, -quantity

Issue confirmed, not sure what the best fix is though.

longwave’s picture

tr’s picture

Component: Code » Product kits

Moving to "Product kit" component.

tr’s picture

Untagging. Only two issues had the uc_product_kit tag. Now that there's a Product kit component the tag is no longer needed.

arhak’s picture

@#6

Issue confirmed, not sure what the best fix is though.

I'm not sure either

possible solution: after editing a product kit, check uc_cart_products and correct as needed
BUT: what happens if I have a browser opened with a shopping cart page and I'm updating the quantities of my products meanwhile an admin removes an item from one of the product kits in my cart ?

arhak’s picture

@#10 for the second part (an admin removes items from a PKit at the time a cart is being updated)

that can be easily handled by uc_product_kit_update_cart_item

uc_product_update_cart_item($p_nid, $product->data, $qty * $kit->products[$p_nid]->qty, $cid);

is just a matter of checking if that $p_nid still belongs to the $kit and if not set its qty to zero

longwave’s picture

Version: 6.x-2.4 » 7.x-3.x-dev
Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new682 bytes

Simplest way to solve this seems to be to remove any matching kits from the cart whenever a kit is updated, same way we do when a kit is deleted. There is no straightforward way to handle product addition or removal at this point, so this seems safest.

Status: Needs review » Needs work

The last submitted patch, 620844-uc_product_kit-update-cart.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

#12: 620844-uc_product_kit-update-cart.patch queued for re-testing.

Failure seems unrelated: exception 'DatabaseSchemaObjectExistsException' with message 'Table variable already exists.'

longwave’s picture

Status: Needs review » Fixed

Committed #12 to 7.x-3.x, ported and committed to 6.x-2.x as well.

Status: Fixed » Closed (fixed)

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