hostagency
Technical User
Hi
I've got a php shopping cart and customers can add discounted bonus buys products to their cart when they buy a full priced product. I have a bonusbuys table created that associates a main product_id with a bonus buy product_id. My problem is that if the customer removes the main product from their cart I need to check the cart contents for associated bonus buys and remove them also. My current working code for removing a product from the cart is this:
case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
$cart->remove($HTTP_POST_VARS['products_id'][$i]);
}
And I need to do something like this but it only deletes one product and one bonus buy, multiple product deletes and bonus buy deletes fail:
case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
$check_for_bonusbuys_query = tep_db_query("select b.bonusbuys_id from bonusbuys b where b.products_id = '" . $HTTP_POST_VARS['products_id'][$i] . "'"
;
$cart->remove($HTTP_POST_VARS['products_id'][$i]);
$check_for_bonusbuys = tep_db_fetch_array($check_for_bonusbuys_query);
if ($check_for_bonusbuys['bonusbuys_id']) {
$check_products = $cart->get_products();
for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
if ($check_products[$i]['id'] == $check_for_bonusbuys['bonusbuys_id']) {
$cart->remove($check_for_bonusbuys['bonusbuys_id']);
}
}
}
Any advice would be most appreciated, I must have something the wrong way round or just wrote some very very bad code.....I'm pretty new to php.
Thanks for your time.
Del
I've got a php shopping cart and customers can add discounted bonus buys products to their cart when they buy a full priced product. I have a bonusbuys table created that associates a main product_id with a bonus buy product_id. My problem is that if the customer removes the main product from their cart I need to check the cart contents for associated bonus buys and remove them also. My current working code for removing a product from the cart is this:
case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
$cart->remove($HTTP_POST_VARS['products_id'][$i]);
}
And I need to do something like this but it only deletes one product and one bonus buy, multiple product deletes and bonus buy deletes fail:
case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
$check_for_bonusbuys_query = tep_db_query("select b.bonusbuys_id from bonusbuys b where b.products_id = '" . $HTTP_POST_VARS['products_id'][$i] . "'"
$cart->remove($HTTP_POST_VARS['products_id'][$i]);
$check_for_bonusbuys = tep_db_fetch_array($check_for_bonusbuys_query);
if ($check_for_bonusbuys['bonusbuys_id']) {
$check_products = $cart->get_products();
for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
if ($check_products[$i]['id'] == $check_for_bonusbuys['bonusbuys_id']) {
$cart->remove($check_for_bonusbuys['bonusbuys_id']);
}
}
}
Any advice would be most appreciated, I must have something the wrong way round or just wrote some very very bad code.....I'm pretty new to php.
Thanks for your time.
Del