I made some changes to the "is_product_valid" routine
I am kind of struggling with the coupon rationale as per my own covenience. My logic is this

if the product is listed in the restriction list, it takes precedence over anything, for either restrict or allow

if the product is not listed, the closest category takes precedence (as in the validate_for_category function)

my new 'is_product_valid' function (in function_generals.php) is

$coupons_query = "SELECT * FROM " . TABLE_COUPON_RESTRICT ."
WHERE coupon_id = '" . (int)$coupon_id . "'
AND product_id = '" . (int)$product_id . "'";
$coupons = $db->Execute($coupons_query);

if ($coupons->RecordCount() > 0 ) {
//if more than one, there is a repeated entry in the restriction table (not logical)
//i will accept the top one
if ( $coupons->fields['coupon_restrict']=='Y') return false;
else return true;
}

$productCatPath = zen_get_product_path($product_id);
$catPathArray = array_merge ( array_reverse(explode('_', $productCatPath)) , array ('-1') ) ;

foreach ($catPathArray as $catPath) {
$sql = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "
WHERE category_id = " . (int)$catPath . "
AND coupon_id = " . (int)$coupon_id;
$result = $db->execute($sql);
if ($result->recordCount() > 0 )
if ($result->fields['coupon_restrict'] == 'N') return true;
else return false;
}
return true;


I ignored the code about taking into account the GIFT word in the model description

I will move it over the ot_coupon class