Jump to content
Sign in to follow this  
bscheiman

Global discount

Recommended Posts

Hey all. I'm trying to code a very simple "coupon-like" contrib that'll allow the admin to configure a global discount (ie, 20%) to be calculated after subtotal but before taxes. So far so good, but I can't seem to get it to work.

 

Example code:

 

	function process() {
  global $order, $currencies;

  if ($this->magic != 1.00) {
	$this->title = $this->title . " (" . number_format(((1.00 - $this->magic) * 100), 0) . "%)";
	$this->desc  = 1.00 - $this->magic;
	$this->output[] = array('title' => $this->title . ':',
							'text' => "-" . $currencies->format($order->info['subtotal'] * $this->desc, true, $order->info['currency'], $order->info['currency_value']),
							'value' => -$order->info['subtotal'] * $this->desc);
  }

}

 

$this->magic holds the discount number (0.8 for 20%). It doesn't seem to modify the end price at all... doesn't even add to it if I remove the sign.

 

Hope someone can enlighten me... Thanks in advance.

Share this post


Link to post
Share on other sites
Hey all. I'm trying to code a very simple "coupon-like" contrib that'll allow the admin to configure a global discount (ie, 20%) to be calculated after subtotal but before taxes. So far so good, but I can't seem to get it to work.

 

Example code:

 

	function process() {
  global $order, $currencies;

  if ($this->magic != 1.00) {
	$this->title = $this->title . " (" . number_format(((1.00 - $this->magic) * 100), 0) . "%)";
	$this->desc  = 1.00 - $this->magic;
	$this->output[] = array('title' => $this->title . ':',
							'text' => "-" . $currencies->format($order->info['subtotal'] * $this->desc, true, $order->info['currency'], $order->info['currency_value']),
							'value' => -$order->info['subtotal'] * $this->desc);
  }

}

 

$this->magic holds the discount number (0.8 for 20%). It doesn't seem to modify the end price at all... doesn't even add to it if I remove the sign.

 

Hope someone can enlighten me... Thanks in advance.

 

this is not the way to do that, this will only display the discount, not process it.


Treasurer MFC

Share this post


Link to post
Share on other sites
this is not the way to do that, this will only display the discount, not process it.

 

 

So... how do I process it? I've decided to use your contrib... but just for the sake of curiousity.

 

Thanks.

Share this post


Link to post
Share on other sites
So... how do I process it? I've decided to use your contrib... but just for the sake of curiousity.

 

Thanks.

 

look at the examples, basically every ot module is a class which manipulates the order information. Mostly order subtotals and totals depending on the sort order, then also puts a display out regarding its discount.

Many even manipulate the tax deductions.


Treasurer MFC

Share this post


Link to post
Share on other sites

There is a contribution called Group Discount v1.4 that you could use to do what you want. I installed it very easily with no problems at all.

 

You can assign a default discount to all customers as a percentage + or -

You can assign discount types to each customer

You can add and delete discount types in admin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×