Administrator
- Join Date:
- Sep 2009
- Location:
- Stuart, FL
- Posts:
- 14,137
- Plugin Contributions:
- 56
First Notifiers upon clicking "add this to my cart"
It's the function actionUpdateProduct (called by /includes/main_cart_actions.php when $_GET['action'] is set to 'update_product') that's biting you. Your code has modified the output (swapping the quantity and price) for the shopping_cart page, e.g. quantity = 1, price = $50.00, while the cart still contains quantity = 50, price = $1.00.
When the "other" product's quantity is updated, that function sees the "quantity = 1" as a replacement for the "quantity = 50" so you'll need to trick it into doing the right thing.
For this case, your best approach is to add another file to the mix: /includes/extra_cart_actions/fix_donation_quantity.php to
check to see if a donation product is already in the cart and is not being deleted (i.e. the quantity set to 0) and, if so, set the posted quantity value to be the quantity that's currently in the cart. Please note that this code assumes that only one donation product will be in the cart at any one time.
if (isset($_GET['action']) && $_GET['action'] == 'update_product') {
for ($i = 0, $n = sizeof($_POST['products_id']); $i < $n; $i++) {
if ($_POST['products_id'] == DONATION_PRODUCT_ID) {
if (! (in_array(DONATION_PRODUCT_ID, (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array())) || $_POST['cart_quantity'][$i] == 0) ){
foreach ($_SESSION['cart']->contents as $uprid => $contents) {
if (((int)$uprid) == DONATION_PRODUCT_ID) {
$_POST['cart_quantity'][$i] = $contents['qty'];
break; // out of foreach
}
}
}
}
}
}