Page 1 of 1

Percentage, instead of float

Posted: Thu Mar 10, 2011 3:33 pm
by SlapStick
Thanks for your help with this, I just can't figure it out as I'm not experienced. I get white pages with the things I've tried.

I'm using a coupon modification for vbulletin and this is the function:

Code: Select all

$coupon_value = $vbulletin->db->query_first("
		SELECT couponvalue, couponname
			FROM " . TABLE_PREFIX . "coupons
			WHERE TO_DAYS(couponvalidto) - TO_DAYS(CURDATE()) > 0
			AND nouses > 0
			AND couponid = '$couponid'
			AND validfor LIKE '%$subscriptionid%'
		");					
		
		$newvalue = floatval($coupon_value['couponvalue']);
		$coupon_name = $coupon_value['couponname'];	

		$value = vb_number_format(($value - $newvalue), 2);
	}
	return $value;
This is the line I need to modify. Basically, I need it to calculate a percentage rather than a float value so it will apply evenly across all subscriptions rather than a flat amount.

Code: Select all

$newvalue = floatval($coupon_value['couponvalue']);
I've tried some different things but they've all wound up in white screens.

Thanks for your help.

Re: Percentage, instead of float

Posted: Thu Mar 10, 2011 3:39 pm
by AbraCadaver
Is couponvalue already meant to be a percentage in the database or is it an amount?

Re: Percentage, instead of float

Posted: Thu Mar 10, 2011 3:59 pm
by SlapStick
I believe it is pulling a value from the database that you set when you create the coupons. It is just an amount in the database.

Image

Re: Percentage, instead of float

Posted: Thu Mar 10, 2011 4:07 pm
by AbraCadaver
So in that example the 10.00 is 10%?

Re: Percentage, instead of float

Posted: Thu Mar 10, 2011 4:44 pm
by SlapStick
AbraCadaver wrote:So in that example the 10.00 is 10%?
Well I want it to apply as a percentage. Currently the plugin is treating it as a flat value that comes off subscriptions. So if I have say, a 1 month option it takes $10 off of that, and a 3 month option that I may have set a lower price on will have $10 off too. Whereas if I use a pct it will come off each sub evenly.

Here is a reply from vbulletin.org where the developer says how to do it, but I don't understand how.

http://www.vbulletin.org/forum/showpost ... ostcount=9

Re: Percentage, instead of float

Posted: Thu Mar 10, 2011 6:55 pm
by SlapStick
Anyone else provide a pointer?