function is_product_valid($product_id, $coupon_id) { global $db; $coupons_query = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "\r\n WHERE coupon_id = '" . (int) $coupon_id . "'\r\n ORDER BY coupon_restrict ASC"; $coupons = $db->Execute($coupons_query); $product_query = "SELECT products_model FROM " . TABLE_PRODUCTS . "\r\n WHERE products_id = '" . (int) $product_id . "'"; $product = $db->Execute($product_query); if (preg_match('/^GIFT/', $product->fields['products_model'])) { return false; } // modified to manage restrictions better - leave commented for now if ($coupons->RecordCount() == 0) { return true; } if ($coupons->RecordCount() == 1) { // If product is restricted(deny) and is same as tested prodcut deny if ($coupons->fields['product_id'] != 0 && $coupons->fields['product_id'] == (int) $product_id && $coupons->fields['coupon_restrict'] == 'Y') { return false; } // If product is not restricted(allow) and is not same as tested prodcut deny if ($coupons->fields['product_id'] != 0 && $coupons->fields['product_id'] != (int) $product_id && $coupons->fields['coupon_restrict'] == 'N') { return false; } // if category is restricted(deny) and product in category deny if ($coupons->fields['category_id'] != 0 && zen_product_in_category($product_id, $coupons->fields['category_id']) && $coupons->fields['coupon_restrict'] == 'Y') { return false; } // if category is not restricted(allow) and product not in category deny if ($coupons->fields['category_id'] != 0 && !zen_product_in_category($product_id, $coupons->fields['category_id']) && $coupons->fields['coupon_restrict'] == 'N') { return false; } return true; } $allow_for_category = validate_for_category($product_id, $coupon_id); $allow_for_product = validate_for_product($product_id, $coupon_id); // echo '#'.$product_id . '#' . $allow_for_category; // echo '#'.$product_id . '#' . $allow_for_product; if ($allow_for_category == 'none') { if ($allow_for_product === 'none') { return true; } if ($allow_for_product === true) { return true; } if ($allow_for_product === false) { return false; } } if ($allow_for_category === true) { if ($allow_for_product === 'none') { return true; } if ($allow_for_product === true) { return true; } if ($allow_for_product === false) { return false; } } if ($allow_for_category === false) { if ($allow_for_product === 'none') { return false; } if ($allow_for_product === true) { return true; } if ($allow_for_product === false) { return false; } } return false; //should never get here }
function numinix_categories_check($categories_list, $products_id, $charge) { if ($categories_list == '') { if ($charge == 1) { return true; } elseif ($charge == 2) { return false; } } else { $categories_array = split(',', $categories_list); $match = false; foreach ($categories_array as $category_id) { if (zen_product_in_category($products_id, $category_id)) { $match = true; break; } } if ($match == true) { return true; } else { return false; } } }
function is_product_valid($product_id, $coupon_id) { global $db; $coupons_query = "select * from " . TABLE_COUPON_RESTRICT . "\r\n where coupon_id = '" . $coupon_id . "'\r\n order by coupon_restrict asc"; $coupons = $db->Execute($coupons_query); $product_query = "select products_model from " . TABLE_PRODUCTS . "\r\n where products_id = '" . (int) $product_id . "'"; $product = $db->Execute($product_query); if (ereg('^GIFT', $product->fields['products_model'])) { return false; } if ($coupons->RecordCount() == 0) { return true; } $product_valid = true; while (!$coupons->EOF) { if ($coupons->fields['product_id'] != 0 && $coupons->fields['product_id'] != $product_id) { $product_valid = false; } if ($coupons->fields['category_id'] != 0 && !zen_product_in_category($product_id, $coupons->fields['category_id']) && $coupons->fields['coupon_restrict'] == 'N') { $product_valid = false; } if ($coupons->fields['product_id'] == (int) $product_id && $coupons->fields['coupon_restrict'] == 'N') { $product_valid = true; } if ($coupons->fields['category_id'] != 0 && zen_product_in_category($product_id, $coupons->fields['category_id']) && $coupons->fields['coupon_restrict'] == 'N') { $product_valid = true; } if ($coupons->fields['product_id'] == (int) $product_id && $coupons->fields['coupon_restrict'] == 'Y') { $product_valid = false; } if ($coupons->fields['category_id'] != 0 && zen_product_in_category($product_id, $coupons->fields['category_id']) && $coupons->fields['coupon_restrict'] == 'Y') { $product_valid = false; } if ($product_valid == true) { break; } $coupons->MoveNext(); } return $product_valid; }
function is_product_valid($pProductHash, $coupon_id) { global $gBitDb; $ret = false; if (is_numeric($coupon_id)) { $ret = TRUE; $query = "SELECT * FROM " . TABLE_COUPON_RESTRICT . " WHERE `coupon_id` = ? ORDER BY " . $gBitDb->convertSortmode('coupon_restrict_asc'); if ($rs = $gBitDb->query($query, array($coupon_id))) { // gifts are not valid, so only check non-gifts if (!preg_match('/^GIFT/', $pProductHash['products_model'])) { $ret = $rs->RecordCount() == 0; // if there are restictions, assume false while ($restriction = $rs->fetchRow()) { // specific product_id - are we exclusive or inclusive? if (!empty($restriction['product_id'])) { if ($restriction['product_id'] == $pProductHash['products_id']) { $ret |= !($restriction['coupon_restrict'] == 'Y'); // Exact match } elseif ($restriction['coupon_restrict'] != 'O') { $ret &= !($restriction['coupon_restrict'] == 'Y'); // Non-optional, must be yes or no } } // specific category_id - are we exclusive or inclusive? if (!empty($restriction['category_id'])) { // check master cat quickly, or go deep diving if ($pProductHash['master_categories_id'] == $restriction['category_id'] || zen_product_in_category($pProductHash['products_id'], $restriction['category_id'])) { $ret |= !($restriction['coupon_restrict'] == 'Y'); // Exact match } elseif ($restriction['coupon_restrict'] != 'O') { $ret &= !($restriction['coupon_restrict'] == 'Y'); // Non-optional, must be yes or no } } // specific product_type_id - are we exclusive or inclusive? if (!empty($restriction['product_type_id'])) { // check master cat quickly, or go deep diving if ($restriction['product_type_id'] == $pProductHash['products_type']) { $ret |= !($restriction['coupon_restrict'] == 'Y'); // Exact match } elseif ($restriction['coupon_restrict'] != 'O') { $ret &= !($restriction['coupon_restrict'] == 'Y'); // Non-optional, must be yes or no } } // specific products_options_values_id - are we exclusive or inclusive? if (!empty($restriction['products_options_values_id'])) { if (!empty($pProductHash['attributes'])) { if (in_array($restriction['products_options_values_id'], $pProductHash['attributes'])) { $ret |= !($restriction['coupon_restrict'] == 'Y'); // Exact match } elseif ($restriction['coupon_restrict'] != 'O') { $ret &= !($restriction['coupon_restrict'] == 'Y'); // Non-optional, must be yes or no } } else { $ret = FALSE; } } } } else { // no restrictions $ret = TRUE; } } } return $ret; }