Just thought i would post on here, for those that are having problems getting this to work with QPBPP or if you have a problem where one of each product (slave) is added to the cart, even if the value is set to 0, Then this is the cause, and the fix below.
If you follow the process of adding an item to the shopping cart.
case 'add_slave' :
// reset($HTTP_POST_VARS);
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
if (substr($key,0,11) == "Qty_ProdId_") {
$prodId = substr($key,11);
$qty = $val;
if(isset($HTTP_POST_VARS["id_$prodId"]) && is_array($HTTP_POST_VARS["id_$prodId"])) {
// We have attributes
$cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$HTTP_POST_VARS["id_$prodId"]))+$qty, $HTTP_POST_VARS["id_$prodId"]);
} else {
// No attributes
$cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
}
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;
If you read the code you can see, Even if the Quantity is Zero, It still makes a call to add_cart - Which is where it all goes wrong and one of each product is added to the cart.
The reason for this is (If you look at the add_cart function
function add_cart($products_id, $qty = '', $attributes = '', $notify = true) {
global $new_products_id_in_cart, $customer_id;
// BOF qpbpp
$pf = new PriceFormatter;
$pf->loadProduct($products_id);
$qty = $pf->adjustQty($qty);
$discount_category = $pf->get_discount_category();
// EOF qpbpp
....
Remembering that even if the Quantity is 0, a call is made to this function, and the very line where it goes wrong is this line here
$qty = $pf->adjustQty($qty);
The Quantity is set to whatever is returned by adjustQty. The adjustQty function is used for when you want to force someone to buy blocks of a product (Such as if you sell a product in packs of 12).
If we dig deeper and go to this adjustQty function,
function adjustQty($qty, $qtyBlocks = NULL) {
...
if ($qty < 1)
$qty = 1;
...
Remember once again, even if the quantity is 0, the function is called, and because the Quantiy is 0 (<1) the quantity value is set to 1.
As such this results in one of every product being added to the cart.
Now, the quick and easy fix for this is to simply not make the call to this function if the Quantity is 0 (As if were not adding anything to the cart, theres no need to make the call!).
Fix
In Application Top, Around line 395 find
case 'add_slave' :
// reset($HTTP_POST_VARS);
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
if (substr($key,0,11) == "Qty_ProdId_") {
$prodId = substr($key,11);
$qty = $val;
if(isset($HTTP_POST_VARS["id_$prodId"]) && is_array($HTTP_POST_VARS["id_$prodId"])) {
// We have attributes
$cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$HTTP_POST_VARS["id_$prodId"]))+$qty, $HTTP_POST_VARS["id_$prodId"]);
} else {
// No attributes
$cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
}
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;
Replace this with the below
case 'add_slave' :
// reset($HTTP_POST_VARS);
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
if (substr($key,0,11) == "Qty_ProdId_") {
$prodId = substr($key,11);
$qty = $val;
if($qty > 0) {
if(isset($HTTP_POST_VARS["id_$prodId"]) && is_array($HTTP_POST_VARS["id_$prodId"])) {
// We have attributes
$cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$HTTP_POST_VARS["id_$prodId"]))+$qty, $HTTP_POST_VARS["id_$prodId"]);
} else {
// No attributes
$cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
}
}
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;
All this fix does is, If the quantity is 0, Don't make the call to add_cart, which will fix the problems with adding one of everything to the cart.