I have this function to return the minimum qty each product can be pruchased. This data is in the table products. It works ok, only that I have some products on sale and the minimum qty for puchasing is higher and assigned in the table specials. How it works is while the product is on sale, the minimum qty should be the one on the table specials instead of the one on the table products. When the special expires, it will return to the minimum qty on table products. // Return quantity buy now function tep_get_buy_now_qty($product_id) { global $cart; $check_min=tep_get_products_quantity_order_min($product_id); $check_units=tep_get_products_quantity_order_units($product_id); $buy_now_qty=1; switch (true) { case ($cart->in_cart_mixed($product_id)==0): if ($check_min >= $check_units) { $buy_now_qty=$check_min; } else { $buy_now_qty=$check_units; } break; default: $buy_now_qty=$check_units; break; } return $buy_now_qty; } This is the query to pull the minimum qty for products on sale. $special_query = tep_db_query("select products_id, products_special_min_qty from specials where products_id = '" . $products_id . "'"); $special = tep_db_fetch_array($special_query); Can anyone give me a hand please. Thanks.
This should do what you described, change your $special_query SQL to this... $special_query = tep_db_query("SELECT P.products_id, IF(COALESCE(products_special_min_qty,0) > products_min_qty, products_special_min_qty, products_min_qty) min_qty FROM products P LEFT JOIN specials S ON P.product_id=S.product_id where P.products_id = '" . $products_id . "'"); PHP: I'm just guessing how your data would be organized, so this code may not be 100% accurate. Basically, the SQL combines the product and specials table, then selects the specials minimum quantity if it is greater than the product's regular minimum quantity.
I'm sorry, this is not what I need. I need to fix the function, not the query. Is someone there who want to get $5 bucks this morning please pm. Thanks
I think you need to fix the query, because I can't see whats the use of the function (you didn't show us) Or I totally misunderstood you. Anyway, from what I understand: if ( /*onsale*/ ) { $table_to_use = 'special'; } else { $table_to_use = 'products'; } $special_query = tep_db_query("select products_id, products_special_min_qty from $table_to_use where products_id = '" . $products_id . "'"); $special = tep_db_fetch_array($special_query); PHP:
Yes, I think you misunderstood what I meant, or even better, I didn't explained this very well. The attached function is working 100% and is returning the value $buy_now_qty correctly. I only need to create a 3rd case inside this function to return $buy_now_qty when the product is in special. The query attached was created to bring products_special_min_qty and is working. I only need to implement the 3RD case inside using this value if the product is in special. Please see the comments inside the function for what I want do. Thanks //This function is working 100%. I only need to create a 3rd case for products on special. function tep_get_buy_now_qty($product_id) { global $cart; //here we bring into this function the minimum quantity when product IS NOT in special // by calling another function (working) $check_min=tep_get_products_quantity_order_min($product_id); $check_units=tep_get_products_quantity_order_units($product_id); $buy_now_qty=1; // Here we created two cases, one when the purchaser had another product on the cart and // the default case which is when there are not products in the shopping cart yet (both working) //THIS IS WHAT I NEED: // I need to create a THIRD case when the product is in special so the variable $but_now_qty should be // the products_special_min_qty. I created the $special_query to pull the products_special_min_qty. // I need only to implement the case. switch (true) { case ($cart->in_cart_mixed($product_id)==0): if ($check_min >= $check_units) { $buy_now_qty=$check_min; } else { $buy_now_qty=$check_units; } break; case //here should be the case for the product if it is in special default: $buy_now_qty=$check_units; break; } return $buy_now_qty; } //This query is working. It brings the products_special_min_qty if the product is in special. I need to use this value to create //the 3RD case in the above function. $special_query = tep_db_query("select products_id, products_special_min_qty from specials where products_id = '" . $products_id . "'"); $special = tep_db_fetch_array($special_query); <? PHP:
Another try: (read the comment in the scripts) (sorry if this doesn't work again) function tep_get_buy_now_qty($product_id) { global $cart; $check_min=tep_get_products_quantity_order_min($product_id); $check_units=tep_get_products_quantity_order_units($product_id); $buy_now_qty=1; // according to your comment "when the product is in special", // I assume if I am able to find the $products_id in table `specials`, "the product is in special" = true $special_check = mysql_query("SELECT products_special_min_qty FROM specials where products_id = '" . $products_id . "' LIMIT 1"); switch (true) { case ($cart->in_cart_mixed($product_id)==0): if ($check_min >= $check_units) { $buy_now_qty=$check_min; } else { $buy_now_qty=$check_units; } break; case (mysql_num_rows($special_check) > 0): // it is in `specials` $special_product = mysql_fetch_assoc($special_check); $buy_now_qty=$special_product['products_special_min_qty']; break; default: $buy_now_qty=$check_units; break; } return $buy_now_qty; } $special_query = tep_db_query("select products_id, products_special_min_qty from specials where products_id = '" . $products_id . "'"); $special = tep_db_fetch_array($special_query); PHP: - ads2help