I've been searching around and I've only came across 1 topic about reusable coupon module.
Now I'm wondering are there any other coupon/discount type of modules around here for e-commerce ?
I'm quite new here and desperately looking for help!

Kind Regards,

Thax

Comments

wmckinley’s picture

I am also interested in this, we might try to build it ourselves.

Wendy

carlhinton’s picture

I'm currently working on a bit of bespoke code to allow coupons - if someone wants to pick up the dirty code and turn it into a module, then I'd be happy

carlhinton’s picture

And here it is - you will have to create yourself a CCK content type of discounts containing a field discount_code_value (the code id) and a boolean field discount_used (whether the code is valid or not) - but anyone can do that

<?php 

function ec_discounts_form_alter(&$form, &$form_state, $form_id) {
	

	if ($form_id == 'ec_checkout_form'){
		
		//Add in discounts
		
		$carried_values = unserialize($_COOKIE['CAT']);
		
		foreach($carried_values as $value) {

			if(is_int((int)$value) && (int)$value !=0 ) {
				$form_state['txn']->misc[] = (object)ec_discounts_get_array($value);
			}
		}
	    
		// Add a field for entering discount codes
		$form['ec_discount'] = array('#type' => 'textfield',
  		  		'#title' => t('Enter a discount code here'),
  		  		'#default_value' => '',
  		  		'#weight' => 4,
				'#maxlength' => 15,
				'#size' => 15,
  				'#required' => FALSE,
  			);
	  			
  		// Add discount code validation
  		
  	    $form['#validate'][] = 'ec_discounts_validate';
		
  	    if (isset($_COOKIE['CAT'])) {
  	    	$form['#ec_discount_list'] = unserialize($_COOKIE['CAT']);
  	    } else {
  	    	$temp_array=array(0=>'No discount codes entered');
  	    	setcookie('CAT',serialize($temp_array));
  	    	$form['#ec_discount_list'] = $temp_array;
  	    }
  	    // Adds to update button
  	    
		
  		$form['buttons']['update']['#submit'][] = 'ec_discounts_form_update';
  		$form['buttons']['order']['#submit'][] = 'ec_discounts_form_order';

		ec_checkout_checkout_form(&$form, &$form_state);
		
	}
}

function ec_discounts_validate($form_id, $form) {

	// Check that entered codes are valid
	if ($form['values']['ec_discount'] != '') {
		if(db_result(db_query("SELECT nid FROM {content_type_discount} WHERE ((field_discount_code_value = '%s') AND (field_discount_used_value = 0))", $form['values']['ec_discount'])) == FALSE){
			form_set_error('ec_discount', t('This is an invalid discount code.'));
		}	
	}
}

// Handle update routine
function ec_discounts_form_update(&$form, &$form_state) {


   
	if ($form['ec_discount']['#value'] != '') {
		if(db_result(db_query("SELECT nid FROM {content_type_discount} WHERE ((field_discount_code_value = '%s') AND (field_discount_used_value = 0))", $form['ec_discount']['#value'])) == FALSE){
			form_set_error('ec_discount', t('This is an invalid discount code.'));
		} else {

			$temp_array=array();
			$temp_array[db_result(db_query("SELECT nid FROM {content_type_discount} WHERE ((field_discount_code_value = '%s') AND 
				(field_discount_used_value = 0))", $form['ec_discount']['#value']))]= 
				db_result(db_query("SELECT nid FROM {content_type_discount} WHERE ((field_discount_code_value = '%s') AND 
				(field_discount_used_value = 0))", $form['ec_discount']['#value']));
			$carried_values = unserialize($_COOKIE['CAT']);
			$temp_array =array_merge($temp_array, $carried_values);
			
			// Remove duplicate codes
			$dupl_array = array();
			foreach ($temp_array as $item){
				$dupl_array[$item] = $item;
			}
			$temp_array=array();
			foreach($dupl_array as $item) {
				$temp_array[] = $item;
			}
			
			// Remove none integers except 'No discount codes entered'
			
			$int_array = array();
			foreach($temp_array as $item){
				if ($item == 'No discount codes entered'){
					$int_array[]=$item;
				} else {
					if ((int)$item !=0 ){
						$int_array[]=$item;
					}
				}
			}
			$temp_array=$int_array;
	
			
			setcookie('CAT',serialize($temp_array));
		}
	}
	



}

// Handle order routine
function ec_discounts_form_order(&$form, &$form_state) {


}


// List discounts nodes
function ec_discounts_get_nodes(){
	$txn = ctools_object_cache_get('transaction', 'ec_donate');
	
	if ($txn->ec_discounts_value == '') {

		$output = array();
	} else {
		
		$output = $txn->ec_discounts_value;
	}

	return $output;
}

// Create the misc array
function ec_discounts_get_array($nid){

	// 0 = pure discount  1=Percentage
	
	$how = db_result(db_query("SELECT field_discount_type_value FROM {content_type_discount} WHERE nid = %d",$nid)); 
	$value = $type = db_result(db_query("SELECT field_discount_value_value FROM {content_type_discount} WHERE nid = %d",$nid)); 	
	if ($type == 0) {
		$result['price'] = -$value;
	}
	$chg=array();
	

	$chg['description'] = 'Discount code: ' . db_result(db_query("SELECT field_discount_code_value FROM {content_type_discount} WHERE nid = %d",$nid));
	$chg['price']=-$value;	
	$chg['type'] ='MT-discount';
	$chg['weight'] = 0;
	$chg['misc_group'] ='Discount';


	return $chg;
	
}
avpaderno’s picture

Issue summary: View changes
Issue tags: -module, -coupon, -HELP, -discount +Discount
avpaderno’s picture

Status: Active » Closed (outdated)

I am closing this issue, as Drupal 6 is now not supported.