Just thought I'd share my experience attempting to use coupons with GCO 1.0.5.
There's a section for adding coupons within the GCO website (Settings->Coupons). "Create and manage coupons to offer discounts to your customers", sounds easy! I added several coupons, and tried it out. Nope, didn't work. I tried to search for documentation regarding this coupon feature, but couldn't find anything at all. I couldn't find anything on the GC merchant forums either. I assume this just doesn't work since there's merchant calculations being done, but I wish I could have found some documentation saying so. If anyone found any documentation regarding using the GCO web admin coupon feature, I'd appreciate it if you could send me a link.
Moving on, I added some coupons in the ZC Coupon Admin and tried it out. It seemed to be working, however (isn't there always a however?), GCO completely ignored the minimum order restriction I specified with the coupon. So you could add any of the coupons regardless of the shopping cart total. So, I had to modify the the calculate_coupons() function within responsehandler.php to reject coupons if the shopping cart didn't reach the minimum order restriction. I only added 4 lines of code, but I've included the whole calculate_coupons() function for googlecheckout/responsehandler.php for those interested:
Code:
function calculate_coupons($root, $data, &$merchant_result, $price=0) {
global $order, $db;
require_once(DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'functions_general.php');
$currencies = new currencies();
require_once(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/discount_coupon.php');
$codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
//print_r($codes);
$first_coupon = true;
foreach($codes as $curr_code) {
$text_coupon_help = '';
//Update this data as required to set whether the coupon is valid, the code and the amount
$coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_code = '" . zen_db_input($curr_code['code']) . "' and coupon_type != 'G'");
if (!$first_coupon || $coupon->RecordCount() < 1) {
// invalid discount coupon code or more than one entered!
$text_coupon_help = $first_coupon?sprintf(TEXT_COUPON_FAILED,$curr_code['code']):'Sorry, only one coupon per order';
$coupons = new GoogleCoupons("false", $curr_code['code'],0, "USD", $text_coupon_help);
$merchant_result->AddCoupons($coupons);
// BBG Start - Invalid discount coupon if coupon minimum order is over 0 and the order total doesn't meet the minimum
} else if ($coupon->fields['coupon_minimum_order']>0 && $order->info['total'] < $coupon->fields['coupon_minimum_order']) {
$text_coupon_help = 'Sorry, the minimum purchase hasn\'t been reached to use this coupon';
$coupons = new GoogleCoupons("false", $curr_code['code'],0, "USD", $text_coupon_help);
$merchant_result->AddCoupons($coupons);
// BBG End
} else {
// valid discount coupon code
$lookup_coupon_id = $coupon->fields['coupon_id'];
$coupon_desc = $db->Execute("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . (int)$lookup_coupon_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'");
$coupon_amount = $coupon->fields['coupon_amount'];
switch ($coupon->fields['coupon_type']) {
case 'F':
$text_coupon_help = 'Discount Coupon: '.$curr_code['code'];
break;
case 'P':
$text_coupon_help = 'Discount Coupon: '.$curr_code['code'];
$coupon_amount = $coupon_amount * $order->info['total'] / 100;
break;
case 'S':
$text_coupon_help = 'Free Shipping Coupon: '.$curr_code['code'];
$coupon_amount = $price;
break;
default:
}
$get_result=$db->Execute("select * from " . TABLE_COUPON_RESTRICT . " where coupon_id='" . (int)$lookup_coupon_id . "' and category_id !='0'");
$cats = '';
while (!$get_result->EOF) {
if ($get_result->fields['coupon_restrict'] == 'N') {
$restrict = TEXT_CAT_ALLOWED;
} else {
$restrict = TEXT_CAT_DENIED;
}
$result = $db->Execute("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' and c.categories_id='" . $get_result->fields['category_id'] . "'");
$cats .= '<br />' . $result->fields["categories_name"] . $restrict;
$get_result->MoveNext();
}
if ($cats=='') $cats = TEXT_NO_CAT_RESTRICTIONS;
$get_result=$db->Execute("select * from " . TABLE_COUPON_RESTRICT . " where coupon_id='" . (int)$lookup_coupon_id . "' and product_id !='0'");
while (!$get_result->EOF) {
if ($get_result->fields['coupon_restrict'] == 'N') {
$restrict = TEXT_PROD_ALLOWED;
} else {
$restrict = TEXT_PROD_DENIED;
}
$result = $db->Execute("SELECT * FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'and p.products_id = '" . $get_result->fields['product_id'] . "'");
$prods .= '<br />' . $result->fields['products_name'] . $restrict;
$get_result->MoveNext();
}
if ($prods=='') $prods = TEXT_NO_PROD_RESTRICTIONS;
$coupons = new GoogleCoupons("true", $curr_code['code'],$coupon_amount,"USD", $text_coupon_help);
$merchant_result->AddCoupons($coupons);
$first_coupon = false;
}
}
}
You can see the lines I've added within the // BBG Start and // BBG End comments.
Disclaimer: This modification was done to fill my particular need, so YMMV.
Shawn
Bookmarks