Post by moonman » Tue Oct 25, 2011 7:18 pm

I use OpenCart 1.5.0 . When I enter coupon code, and there are 2 options below: "Uses Per Coupon:" and "Uses Per Customer:" . So I tryed to enter 1 or 2. This means that this coupon can be used only once? The problem is that I can use the coupon unlimited time, until date is expired. How can I fix this? Why this limitation is not working for me?

p.s. I have also noticed, after coupon been used, the "Coupon History" menu, is still blank.

Newbie

Posts

Joined
Tue Oct 25, 2011 7:11 pm

Post by Daniel » Tue Oct 25, 2011 9:50 pm

update to 1.5.1 this has already been fixed.


i think it was a bug in only 1.5.0

you can check the svn to fix it manually.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by snorkeltwin » Sun Nov 13, 2011 9:39 am

I am having this same issue running 1.5.1.

Works correctly when using Cash on Delivery as the payment method, but has exactly the same problem when using Paypal.

Newbie

Posts

Joined
Sun Nov 13, 2011 2:29 am

Post by ddowdall » Wed Dec 07, 2011 2:19 am

I am using 1.5.1 and just discovered there is only 1 entry in the coupon_history table.

During the past few weeks, there has been several coupons used. If you went to each order individually you can see the coupon used, however, the coupon_history table only has 1 item. :(

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Wed Dec 07, 2011 4:56 am

Just in case it may not be resolved since even I see this problematic from v1.5.1.3 release (fresh installation),

In your catalog/model/checkout/coupon.php file,

find:

Code: Select all

public function redeem($coupon_id, $order_id, $customer_id, $amount) {
		$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_history` SET coupon_id = '" . (int)$coupon_id . "', order_id = '" . (int)$order_id . "', customer_id = '" . (int)$customer_id . "', amount = '" . (float)$amount . "', date_added = NOW()");
	}
replace with:

Code: Select all

public function redeem($coupon_id, $order_id, $customer_id, $amount) {
		$sql = "INSERT INTO " . DB_PREFIX . "coupon_history
				(coupon_id, order_id, customer_id, amount, date_added)
				VALUES(" . (int)$coupon_id . ", " . (int)$order_id . ", " . (int)$customer_id . ", " . (float)$amount . ", NOW())
			   ";

		$this->db->query($sql);
	}	
This should definitely fix the problem.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ddowdall » Wed Dec 07, 2011 6:38 am

Thank you very much for your help. I'm going to try this code right now. ;D

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Wed Dec 07, 2011 6:53 am

No problem. Although, take note that all previous transactions due to the wrong code used before my modification above can't be recovered as only starting from the next order after this implementation, you will see the next results on your coupon history table.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ddowdall » Wed Dec 07, 2011 7:31 am

Hi, Do you see any reason why this would not work when the person makes the payment with paypal standard?

I tested your code above and it works when using free checkout(store credit) but not with a real payment using PayPal.

Thanks for your help!

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Wed Dec 07, 2011 7:59 am

ddowdall wrote:Hi, Do you see any reason why this would not work when the person makes the payment with paypal standard?

I tested your code above and it works when using free checkout(store credit) but not with a real payment using PayPal.

Thanks for your help!
While using Paypal for instance, what is your payment status right now ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ddowdall » Thu Dec 08, 2011 1:40 am

PayPal payment sets the status to "Payment Received" which is a status I added to the list.

Then when the order gets shipped the status is changed to "Shipped"

Does the code look for a specific status?

Thanks

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Thu Dec 08, 2011 1:54 am

This seem to be a related case on why it doesn't work as intended in order to either process the confirmation from Paypal Standard nor an update when needed since the 'shipped' statement is not included whenever the order is verified or unverified ... ???

Let me create a new configuration key for you and once published it would be great to tell me if it does update accordingly on the next testing order from Paypal Standard.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Thu Dec 08, 2011 2:10 am

In admin/controller/payment/pp_standard.php file,

find:

Code: Select all

if (isset($this->request->post['pp_standard_voided_status_id'])) {
			$this->data['pp_standard_voided_status_id'] = $this->request->post['pp_standard_voided_status_id'];
		} else {
			$this->data['pp_standard_voided_status_id'] = $this->config->get('pp_standard_voided_status_id');
		}
add after:

Code: Select all

if (isset($this->request->post['pp_standard_shipped_status_id'])) {
	$this->data['pp_standard_shipped_status_id'] = $this->request->post['pp_standard_shipped_status_id'];
} else {
	$this->data['pp_standard_shipped_status_id'] = $this->config->get('pp_standard_shipped_status_id');
}
Then, find:

Code: Select all

$this->data['entry_voided_status'] = $this->language->get('entry_voided_status');
add after:

Code: Select all

$this->data['entry_shipped_status'] = $this->language->get('entry_shipped_status');
In admin/language/english/payment/pp_standard.php file,

find:

Code: Select all

$_['entry_voided_status']		     = 'Voided Status:';
add after:

Code: Select all

$_['entry_shipped_status']		     = 'Shipped Status:';
In your catalog/controller/payment/pp_standard.php file,

find:

Code: Select all

case 'Voided':
	$order_status_id = $this->config->get('pp_standard_voided_status_id');
	break;
add after:

Code: Select all

case 'Shipped':
        $order_status_id = $this->config->get('pp_standard_shipped_status_id');
        break;
In admin/view/template/payment/pp_standard.tpl file,

find:

Code: Select all

<tr>
            <td><?php echo $entry_voided_status; ?></td>
            <td><select name="pp_standard_voided_status_id">
                <?php foreach ($order_statuses as $order_status) { ?>
                <?php if ($order_status['order_status_id'] == $pp_standard_voided_status_id) { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
add after:

Code: Select all

<tr>
            <td><?php echo $entry_shipped_status; ?></td>
            <td><select name="pp_standard_shipped_status_id">
                <?php foreach ($order_statuses as $order_status) { ?>
                <?php if ($order_status['order_status_id'] == $pp_standard_shipped_status_id) { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
These modifications should clarify this situation.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ddowdall » Thu Dec 08, 2011 2:14 am

Thank you!!! I will give it a try and will let you know what happens.

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by ddowdall » Thu Dec 08, 2011 4:24 am

Well, it is still not recording to the coupon_history table. I tried 3 times. :bang:

I tried to add "Payment Received" to the catalog/controller/payment/pp_standard switch case using the same code as the "Complete" case

I even tried to put the redeem function back to the original code.

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Thu Dec 08, 2011 5:11 am

Keep the previous change.

Then, go to catalog/model/checkout/order.php file,

find twice:

Code: Select all

// Send out any gift voucher mails
if ($this->config->get('config_complete_status_id') == $order_status_id) {
	$this->load->model('checkout/voucher');

	$this->model_checkout_voucher->confirm($order_id);
}
replace both with:

Code: Select all

// Send out any gift voucher mails
if ($this->config->get('config_complete_status_id') == $order_status_id) {
	$this->load->model('checkout/voucher');

	$this->model_checkout_voucher->confirm($order_id);

        $this->load->model('checkout/coupon');
        
        $this->model_checkout_coupon->confirm($order_id);
}
Then, it would seem there's a missing routine from the catalog/model/checkout/coupon.php file and the reason why people never receives an email regarding a discount after a purchase is complete. I also found the issue on why the gift voucher isn't being sent appropriately after an order which I will post on a new topic after this post momentarily.

Find:

Code: Select all

public function redeem($voucher_id, $order_id, $amount) {
add above:

Code: Select all

public function confirm($order_id) {
		$this->load->model('checkout/order');
		
		$order_info = $this->model_checkout_order->getOrder($order_id);
		
		if ($order_info) {
			$this->load->model('localisation/language');
			
			$language = new Language($order_info['language_directory']);
			$language->load($order_info['language_filename']);	
			$language->load('mail/coupon');
			
			$coupon_query = $this->db->query("SELECT *, cp.product_id AS coupon_product_id FROM `" . DB_PREFIX . "coupon` c INNER JOIN " . DB_PREFIX . "coupon_history ch ON (ch.coupon_id = c.coupon_id) LEFT JOIN " . DB_PREFIX . "coupon_product cp ON (cp.coupon_id = ch.coupon_id) WHERE ch.order_id = '" . (int)$order_id . "'");
			
			$this->load->model('catalog/product');
			
			foreach ($coupon_query->rows as $coupon) {
				$product_info = $this->model_catalog_product->getProduct($coupon['coupon_product_id']);
				
				// HTML Mail
				$template = new Template();
				
				$template->data['title'] = sprintf($language->get('text_subject'), $coupon['name']);
				
				$template->data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($coupon['total'], $order_info['currency_code'], $order_info['currency_value']));
				$template->data['text_from'] = sprintf($language->get('text_from'), $order_info['store_name']);
				$template->data['text_message'] = $language->get('text_message');
				$template->data['text_redeem'] = sprintf($language->get('text_redeem'), $coupon['code']);
				$template->data['text_footer'] = $language->get('text_footer');
				
				$template->data['store_name'] = $order_info['store_name'];
				$template->data['store_url'] = $order_info['store_url'];
				$template->data['message'] = (isset($product_info) && !empty($product_info)) ? $product_info['name'] : '';
			
				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/coupon.tpl')) {
					$html = $template->fetch($this->config->get('config_template') . '/template/mail/coupon.tpl');
				} else {
					$html = $template->fetch('default/template/mail/coupon.tpl');
				}
					
				$mail = new Mail(); 
				$mail->protocol = $this->config->get('config_mail_protocol');
				$mail->parameter = $this->config->get('config_mail_parameter');
				$mail->hostname = $this->config->get('config_smtp_host');
				$mail->username = $this->config->get('config_smtp_username');
				$mail->password = $this->config->get('config_smtp_password');
				$mail->port = $this->config->get('config_smtp_port');
				$mail->timeout = $this->config->get('config_smtp_timeout');			
				$mail->setTo($coupon['to_email']);
				$mail->setFrom($this->config->get('config_email'));
				$mail->setSender($order_info['store_name']);
				$mail->setSubject(sprintf($language->get('text_subject'), $order_info['store_name']));
				$mail->setHtml($html);
				$mail->send();		
			}
		}
	}
Then, copy the catalog/view/theme/x/template/mail/voucher.tpl as coupon.tpl (copy, don't rename) under the same folder.

Then, in your catalog/language/english/mail folder, create a new file named: coupon.php .

Then, add the following:

Code: Select all

<?php
// Text
$_['text_subject']  = 'You have received a %s coupon';
$_['text_greeting'] = 'Congratulations, You have received a discount worth %s';
$_['text_from']     = 'This coupon has been sent to you by %s';
$_['text_message']  = 'With a message saying';
$_['text_redeem']   = 'To redeem this coupon, write down the redemption code which is <b>%s</b> then click on the the link below and purchase the product you wish to use this coupon on. You can enter the coupon code on the shopping cart page before you click checkout.';
$_['text_footer']   = 'Please reply to this email if you have any questions.';
?>
This should fix the reason entirely on why you see no difference regarding the coupon once an order is complete from no matter which payment type is being used.
Last edited by straightlight on Sat Dec 10, 2011 7:59 am, edited 1 time in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Thu Dec 08, 2011 5:34 am

Corrections has been made from the post above in order to use specific products with coupons which customers will also be advised on which product specifically the coupon(s) can be used.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ddowdall » Sat Dec 10, 2011 7:48 am

Hi, I am sorry to say it still does not save to the coupon_history table.

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by straightlight » Sat Dec 10, 2011 7:58 am

Do you receive the coupon email notification since the above modifications ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by angelaho » Thu Jan 05, 2012 8:18 pm

how about for open cart 1.53?
coupon limitation doesn't work, and when i've used ur script, the whole site went down and error displayed.. pls help! thanks!

Newbie

Posts

Joined
Fri Dec 23, 2011 1:48 pm

Post by angelaho » Thu Jan 05, 2012 8:23 pm

angelaho wrote:how about for open cart 1.53?
coupon limitation doesn't work, and when i've used ur script, the whole site went down and error displayed.. pls help! thanks!
coupon history doesn't show either, as well as coupon limitation..! pls help thanks!

Newbie

Posts

Joined
Fri Dec 23, 2011 1:48 pm
Who is online

Users browsing this forum: Amazon [Bot] and 35 guests