Unique Coupon

  • Posts: 3
  • Thank you received: 0
12 years 11 months ago #33035

Hello
I just purchased business version, looking for extra restriction over coupons.
Is it possible to create one coupon that any user can use a predefine time, and mostly only once ?

I try this code below, but it comes to conflict with the coupon removal process.

I'm sure you'll be able to implement this very easely :

function check_coupon(){
	// restricted usage numbers
	$user=&JFactory::getUser();
	$db	=& JFactory::getDBO();
	$coupon = JRequest::getString('coupon','');
	if(!empty($coupon)){
		$db->setQuery("SELECT COUNT(order_id) FROM #__hikashop_order AS o".
		" LEFT JOIN #__hikashop_user AS u ON o.order_user_id=u.user_id".
		" WHERE u.user_cms_id=".$user->id.
		" AND o.order_discount_code='".$coupon."'"
		);	
		$already = $db->loadResult();
		// the number 1 below might be replaced with a parameter from the backend
		if ($already>1){	
			$app =& JFactory::getApplication();
			$app->enqueueMessage(JText::_('COUPON_ALLREADY_USED'));
			return false;
		} else {
			return true ;			
		}
	} else {
		return true;
	}
}

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 11 months ago #33059

Yes you can do that.
Just select an end date for the coupon and set a user quota of 1 in your coupon and that will do what you want. You don't have to change any code for that.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
12 years 11 months ago #33074

Is the quota relative to client, or absolute ?
I mean I need the same coupon to be used once per user, not once for every users...

How does it work then ?

Thanks in advance :)

Last edit: 12 years 11 months ago by giboo.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 11 months ago #33083

If you look at the options of the coupon, both options exists: quota and quota per user.
So you can do both.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
12 years 11 months ago #33138

Thank you : I've been watching standard options for too long, and not enough business ones :laugh:

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum