Post by tchemis » Tue Sep 11, 2007 8:25 am

Hi Daniel,

There seems to be a little bug with the coupon system. Discounts are applied to the Final Total, they should be applied to the Item Price only.

For Example, If I have a product for 1.00, and shipping to 1.00, and create a coupon to give 60% off and free shipping, The total will become a negative number. Because of this. 

Active Member

Posts

Joined
Tue Aug 21, 2007 9:23 am

Post by garretn » Tue Oct 16, 2007 10:18 am

I just ran in to this problem today myself, and took it upon myself to fix it. ;)

Open this file:

catalog/extension/calculate/coupon.php

Change all occurrences of getTotal() to getSubtotal(), save the file. I believe there should be four total, all under the calculate function.

That is the only change needed. ;)

Newbie

Posts

Joined
Sun Sep 09, 2007 10:03 am

Post by tchemis » Wed Oct 17, 2007 6:31 am

Cool, thanks I will try this out today, post back any success.

Active Member

Posts

Joined
Tue Aug 21, 2007 9:23 am

Post by ven.ganeva » Tue Jul 15, 2008 11:34 pm

Hey where can i download this extension please?  ??? i don't care about the bug cos actually it works as i want it to...

Newbie

Posts

Joined
Mon Apr 07, 2008 6:45 pm

Post by Luvz2drv » Tue Jul 15, 2008 11:42 pm

its in the core package not an add on

Global Moderator

Posts

Joined
Fri Mar 21, 2008 10:58 am

Post by ven.ganeva » Tue Jul 15, 2008 11:52 pm

Why don't i have it in my core package? is it not in v 0.6.5? because my crapy hosting company have PHP4 on the server.  :'( is it possible for someone to post that folder and maybe i can just add it on, or is that just wishful thinking??

Newbie

Posts

Joined
Mon Apr 07, 2008 6:45 pm

Post by dennisforrest » Sat Aug 02, 2008 4:12 am

Hi All,

the "getSubtotal()" workaround is wrong when a customer add products with discount and products without discount in the same cart.

Using the getSubtotal fix, for example, if I have in my shop the "product 1" that have a 10% discount, and "product 2" that have no discount and I add all the two products in my cart, I get:

product 1: 10 euro
product 2: 5 euro
subtotal: 15 euro
discount 10% = 1,5 euro

but, it is wrong, because discount must be applied only to "product 1", so the discount 10% = 1 euro.

Here, put the code to fix this problem correctly:

Edit the file catalog\extension\calculate\coupon.php, and replace the calculate() function, with this one:

Code: Select all

	function calculate() {
		$total_data = array();

		if (($this->config->get('coupon_status')) && ($this->coupon->getId())) {

			//apply discount only for products into coupon rule
			$totalCouponProductPrice = 0;
			foreach ($this->coupon->product as $result) {
				$data[] = $result['product_id'];
			}
			foreach ($this->cart->getProducts() as $result) {
				if (in_array($result['product_id'], $data)) {
					$totalCouponProductPrice = $totalCouponProductPrice + ( $result['price'] * $result['quantity']);
				}
			}

			if ($this->coupon->getDiscount($totalCouponProductPrice) > 0) {
      			$total_data[] = array(
        			'title' => $this->language->get('text_coupon_title', $this->coupon->getName()),
	    				'text'  => '-' . $this->currency->format($this->coupon->getDiscount($totalCouponProductPrice)),
        			'value' => $this->coupon->getDiscount($totalCouponProductPrice)
      			);
				
				$this->cart->decreaseTotal($this->coupon->getDiscount($totalCouponProductPrice));
			}
						
			if (($this->coupon->getShipping()) && ($this->cart->hasShipping())) {
      			$total_data[] = array(
        			'title' => $this->language->get('text_coupon_shipping'),
	    			'text'  => '-' . $this->currency->format($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')))),
        			'value' => $this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method')))
      			);
							
				$this->cart->decreaseTotal($this->tax->calculate($this->shipping->getCost($this->session->get('shipping_method')), $this->shipping->getTaxClassId($this->session->get('shipping_method'))));
			}
		}
	
		return $total_data;
	}

Newbie

Posts

Joined
Tue Aug 07, 2007 7:55 pm

Post by Heilong » Wed Sep 24, 2008 2:34 pm

Thanks for the fix.

I'm using version 0.7.8 and it works great.

New member

Posts

Joined
Mon Sep 01, 2008 5:57 pm
Who is online

Users browsing this forum: No registered users and 8 guests