Page 2 of 2

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Sat Jan 23, 2016 7:26 pm
by stokeyblokey
My thanks to jolyonr for the fix - yet another unaddressed bug carried forward from previous versions, have to say it is disappointing to see so many things that don't work properly by default...community edition next time I think! :)

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Tue Sep 27, 2016 8:37 pm
by shaftoe
Unbelievably this problem still persists in OC 2.2. This solution works okay but it remains 'just a fix'. I'll put it in as a Bug for 2.2 as well.

Re: [1.5.x] Coupon History not working with Paypal, etc - FIXED!

Posted: Sat Oct 14, 2017 12:45 am
by mutluh
I think the problem is in /catalog/model/total/coupon.php around line 200 for Version 2.1.0.1

Code: Select all

		if ($code) {
			$coupon_info = $this->getCoupon($code);

			if ($coupon_info) {
				$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_history` SET coupon_id = '" . (int)$coupon_info['coupon_id'] . "', order_id = '" . (int)$order_info['order_id'] . "', customer_id = '" . (int)$order_info['customer_id'] . "', amount = '" . (float)$order_total['value'] . "', date_added = NOW()");
			} else {
				return $this->config->get('config_fraud_status_id');
			}
		}
When $coupon_info calls the function getCoupon it returns nothing, as the function also has other variables from the cart, and the cart is emptied while the system checks for payment confirmation. However, in the confirm function we don't need any of these variables, but coupon_id only. Thus, to correct the problem, i created another function called getCouponInfo to call coupon_id. As i am new to PHP and coding it might not be the best solution but it worked for me. I inserted the code as below.

Code: Select all

	public function getCouponInfo($code) {
		$status = true;

		$coupon_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon` WHERE code = '" . $this->db->escape($code) . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) AND status = '1'");

		if ($status) {
			return array(
				'coupon_id'     => $coupon_query->row['coupon_id'],
			);
		}
	}
	public function confirm($order_info, $order_total) {
		$code = '';

		$start = strpos($order_total['title'], '(') + 1;
		$end = strrpos($order_total['title'], ')');

		if ($start && $end) {
			$code = substr($order_total['title'], $start, $end - $start);
		}

		if ($code) {
			$coupon_info = $this->getCouponInfo($code);

			if ($coupon_info) {
				$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_history` SET coupon_id = '" . (int)$coupon_info['coupon_id'] . "', order_id = '" . (int)$order_info['order_id'] . "', customer_id = '" . (int)$order_info['customer_id'] . "', amount = '" . (float)$order_total['value'] . "', date_added = NOW()");
			} else {
				return $this->config->get('config_fraud_status_id');
			}
		}
	}
To simplify, i changed getCoupon to getCouponInfo, and added the getCouponInfo function. Hope it will solve some people's problem, as it took me days to find the problem :D

Re: [1.5.x] Coupon History not working with Paypal, etc - FIXED!

Posted: Thu Oct 26, 2017 7:38 pm
by ocam
I know this is an old topic... The fix from jolyonr works only partially for me (Version 1.5.4). When applied, an entry is created in the coupon history table, however, the coupon_id is missing. Also, there are numerous error messages in the error log: undefined index, all related to the return array:

Code: Select all

return array(
				'coupon_id'     => $coupon_query->row['coupon_id'],
				'code'          => $coupon_query->row['code'],
				'name'          => $coupon_query->row['name'],
				'type'          => $coupon_query->row['type'],
				'discount'      => $coupon_query->row['discount'],
				'shipping'      => $coupon_query->row['shipping'],
				'total'         => $coupon_query->row['total'],
				'product'       => $coupon_product_data,
				'date_start'    => $coupon_query->row['date_start'],
				'date_end'      => $coupon_query->row['date_end'],
				'uses_total'    => $coupon_query->row['uses_total'],
				'uses_customer' => $coupon_query->row['uses_customer'],
				'status'        => $coupon_query->row['status'],
				'date_added'    => $coupon_query->row['date_added']
			);
So the arrays are not recognized after the fix has been applied. Any suggestions how to prevent that error?

Re: [1.5.x] Coupon History not working with Paypal, etc - FIXED!

Posted: Thu Oct 26, 2017 10:49 pm
by ADD Creative
The problem could be that coupon code is not being found in the database. You can stop the errors by changing:

Code: Select all

if (($status)||($noverify)) {
	return array(
To:

Code: Select all

if (($status || $noverify) && $coupon_query->num_rows) {
	return array(
However that won't stop the issue of $coupon_query not being filled from the database.