Gift voucher mails not sent automatically!! #3093

Closed
cutzenfriend opened this Issue Jun 8, 2015 · 32 comments

Projects

None yet

8 participants

@cutzenfriend

OC 2.0.3.1 with latest patches

When a customer buys a Gift Voucher, and this order becomes complete in the back end an confirmation email is sent to buyer.
Everyone receives an email. admin - customer (so mail is working!)
However the gift voucher recipient never receives the email for this gift voucher, not on purchase, not on any Order state.

The admin\controller\sale\voucher.php has the correct mail functions, i just think it is never triggered.

In other words.

Customer buys voucher > checks out -> order containing voucher is pending/processing status
At this point voucher is added but wont WORK on checkout yet. No email should be sent to voucher recipient at this point. That's good and expected.

However...
Customer order that contains voucher payment is confirmed -> order status becomes Complete
At this point voucher becomes usable and validated. However no notification email is sent to voucher recipient.

Cant seem to find in the code where the complete status of the order updates the voucher AND triggers the notification email for the voucher recipient.

I will try to investigate further why.
If anyone one knows please help?

This ticket is reopened!

@stockmaster
Contributor

This was reported many times before. Daniel will just close and not listen as usual
as per #2937 (comment)
and #2950

@cutzenfriend

This would be very bad... Another issue with vouchers is, that every voucher can be used multiple times even if it is set to once per customer because they get deactived only if the order is set to complete!

@stockmaster
Contributor

@cutzenfriend Are you saying that, until the order where the Voucher is used gets a status of Complete, the "balance" is not deducted from the voucher and it can be - meanwhile - reused for payment on another order?

If so, wouldnt the consequent orders fail to complete once the original order is processed and Complete?

@cutzenfriend

@stockmaster Are you saying that, until the order where the Voucher is used gets a status of Complete, the "balance" is not deducted from the voucher and it can be - meanwhile - reused for payment on another order?

This is exactly what happens. The complete amount of the voucher is usable multiple times until at least one order where the voucher was used is set to complete....

@stockmaster
Contributor

@cutzenfriend I am unsure if Daniel will read this. However if he does maybe this needs addressing, as per IF voucher used -> lock value untill complete.
Clearly voucher engine needs tweaking.

Fingers crossed we dont get closed without comment ;)

@OpenCartAddons
Contributor

The vouchers/coupons will be confirmed (subtracted) when the order reaches one of the selected Processing or Complete order statuses in the store settings under System > Settings > YourStore > Options > Processing Order Status & Complete Order Status.

The call for this is in the addOrderHistory function in the file catalog/model/checkout/order. The call starts on line 317.

Edit:
This is also when the product stock is subtracted and other operations are performed to "Complete" the order.

Joel.

@stockmaster
Contributor

@OpenCartAddons Understood however doesnt address the problem presented by cutzenfriend. If the same voucher can be used to initiate multiple orders, in effect its duplicating "value" untill ONE is complete. The question is what happens when the other orders try to get complete status?

@OpenCartAddons
Contributor

@stockmaster I see your point. The system will check to see if the voucher is valid during the confirm call, but if the voucher is invalid it only returns a value of false. There is no warning to the shop owner that the voucher in the order is invalid.

A warning should be applied to the order or the order is set to a predefined order status to alert the administrator that the order may be fraudulent. This should apply to invalid coupons as well.

@stockmaster
Contributor

@OpenCartAddons Exactly. Or a Voucher should be assigned a "in use" budget if used in another order, even if not fully commited to it.

But we have here 2 different problems.
a) the voucher recipient never receives the confirmation via email he/she got a voucher in the first place as the original Issue post. That been reported several times before.
b) the mechanics of how the voucher is used might need a review.

@OpenCartAddons
Contributor

I think I've found the issue. Based on the code, the voucher is only confirmed on line 857 if the previous order status was 0 (missing) and the new order status is set to complete.

There should be an additional call made in the addOrderHistory function when the old order status is complete and the new order status is anything else (pending, refunded, etc.), the disableVoucher function should be called. $this->model_checkout_voucher->disableVoucher($order_id);

@stockmaster
Contributor

@OpenCartAddons I see you digging deeper than my knowladge would allow me. you dont seem to be able to pinpoint why - when a voucher is bought and payment confirmed for IT - the recipient never recieves the Email? pretty please? :D

@OpenCartAddons
Contributor

@stockmaster Try replacing line 853 in catalog/model/checkout/order.php

Replace This:
if (in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {

With This:
if (in_array($order_status_id, $this->config->get('config_complete_status'))) {

I believe the wrong order_status_id variable is being used to check if the order is set to complete. $order_info['order_status_id'] should be the previous order status, where as $order_status_id is the new order status.

@stockmaster
Contributor

@OpenCartAddons Would you then agree with me and @cutzenfriend that Theres bugs in the Voucher engine? be it the emission of the email confirmation to the Voucher Recipient and the Voucher order processing?

Because i been trying to point this to Daniel for months now and all i get is.. Nothing!

@OpenCartAddons
Contributor

@stockmaster Yes, there was a bug in the code. I've submitted a pull request #3095

I just tested v2.0.3.1 and the gift voucher confirmation email is only sent if the previous order status was complete, when it should send when the current order status is complete.

The wrong variable was used in the code for the order_status_id.

Cheers,
Joel.

@stockmaster
Contributor

Wonderful! So if i got you right, if customer X buys Voucher addressed to recipient@opencartisawesome.com -> and the store owner makes said order as Complete, then Recipient will recieve an email saying "You got an voucher to spend" of sorts correct?

Now we just need to fix the other error that was reported on the voucher utilization! :)

NICE Job! thank you

@OpenCartAddons
Contributor

@stockmaster Correct. This functionality is already in OpenCart, it's just the wrong order_status_id was being used to determine whether the email was sent or not. Instead of looking at the new order_status_id, it was looking at the old order_status_id.

You can get the emails to send for the time being by setting the order status to complete twice, or if the order status is already set to complete, just add another order history and mark it as complete again.

I would recommend that you do not check the box to notify the customer when doing this as it will spam the customer who purchased the voucher with order update notifications.

@stockmaster
Contributor

@OpenCartAddons as i suspected.
Which will have me say. THANK YOU OpencartAddons for making my suspecions and report #2937 acurate and for @danielkerr EAT that! LOL!

@cutzenfriend

You guys are awesome! @OpenCartAddons I will try to implement your fix #3095 manually tomorrow. I will give you feedback about this.

Could you also address the other issue with the voucher?

@OpenCartAddons
Contributor

@cutzenfriend @stockmaster While it is technically possible to complete two orders using the same voucher, it would happen under extremely rare circumstances.

From what I can tell by the code and doing some of my own testing, I found two scenarios where someone could possibly abuse this:

Multiple Tabs Using Offsite Payment Pages (i.e. PayPal Standard)
I didn't actually test this one, but it may be possible. A customer creates an order and is transferred to a separate payment page such as PayPal Standard. The customer then opens another tab and goes through the checkout process again, this time selecting a different payment method that also has an offsite payment page. The customer then completes the payment via the first payment page, and completes the payment via the second payment page. The customer has now paid for the order with the voucher amount deducted from the order. There is no warning in the admin panel indicating that this order may be fraudulent, and if the administrator isn't looking through the order totals it can go undetected.

If Your Order Status Settings Are Not Setup Correctly
I did test this one and can confirm that it happens. If the administrator doesn't setup their order status settings correctly this scenario can easily happen. The gift voucher only has the order value deducted when the order reaches either one of the Processing or Completed order statuses setup in Admin CP > System > Settings > YourStore [edit] > Options (tab). You would need to ensure that when a payment gateway receives the callback, that the order is correctly assigned to either a Processing or Completed order status, If your payment gateway doesn't do this, then multiple orders can be processed using the same voucher code until one of the orders using the voucher is updated to the correct order status to trigger the voucher confirm function.

The only way around this that I can think of is to create a special order status, and have the voucher confirm function return an error message if the voucher has already been used in another order. If the error message is detected, then the order is flagged and the order status is changed. This would at least give the administrator a heads up that something fishy is going on with the order and to double check everything.

Joel.

@stockmaster
Contributor

@OpenCartAddons That is a great indepth analisys which puts technical skilled words in what both me and @cutzenfriend suspected.

Maybe with your feedback @danielkerr or @jamesallsup could have a look into this situation and a) push your commit into master asap, and b) optimize the way the vouchers are manipulated as per your second scenario.
I believe your first scenario, although relevant, as you pointed out would be less plausible and clearly done with malice in purpose by the buyer side.

Once again thank you very much for the time you dedicated into this issue. Might not seem very relevant but is never the less a set of bugs and concerns that would make opencart more robust if addressed!

Regards

@AshrafSello

The gift voucher must be set to disabled automaticaly once it's applied no matter the order completed or not, if the order not completed the admin can reactivate the voucher if customer not complete the order and complain occured, this is the straight forward solution for the gift voucher problem i am facing in my issue #3067

@cutzenfriend

@AshrafSello That's exactly what I thought! It has to be done this way.

@OpenCartAddons
Contributor

@AshrafSello @cutzenfriend This would add a lot of headaches for the store administrator.

Every time a customer gets to the last step of the checkout, an order is created within OpenCart. This means that if the customer realizes that they made a mistake in their order and go back to correct it, their gift voucher is no longer valid and they have to contact the store administrator to fix it.

In addition to that there is currently no way for the store administrator to remove history from a gift voucher. This means the store administrator would have to change the order history of the "missing" order to completed, then back to an order status that is no selected in the Processing or Completed order status list. This is what currently triggers the function to remove transaction history from the voucher.

Disabling the gift voucher for incomplete orders is not the way to deal with this. It adds too many problems for both customers and store administrators.

Joel.

@danielkerr
Contributor

we can add a order status for orders to be looked at. if the coupon has already been used.

@AshrafSello

At least set the gift voucher to disabled if the checkout operation has been done completely even if the order status still pending or processing or.......... Till completed, no need to wait to completed status, i checked that in th COD order the gift voucher did not set to disabled when the checkout operation completed.

@OpenCartAddons
Contributor

@AshrafSello This is an issue with your order status setup. Make sure that all the correct order statuses are selected for both Processing and Completed within the store settings

Admin CP > System > Settings > Your Store [edit] > Options (tab) > Processing Order Statuses
Admin CP > System > Settings > Your Store [edit] > Options (tab) > Complete Order Statuses

When the status of the order reaches any of the selected order statuses in the Processing or Complete list, then the coupon / voucher will be deducted.

Also, you will want to ensure that all your payment gateways are setup to set the order to one of the selected order statuses once payment has been completed or the order is confirmed.

Regards,
Joel.

@JeffroDH

Thank you @OpenCartAddons for the writeup.

@danielkerr danielkerr closed this Aug 15, 2015
@danielkerr danielkerr added a commit that referenced this issue Aug 15, 2015
@danielkerr danielkerr #3093 b57c307
@danielkerr
Contributor

sorry closed and reopened as this needs a better fix

@danielkerr danielkerr reopened this Aug 16, 2015
@munirasim

Even if the orders Status are set correctly, the email won't be sent automatically in OC 2.0.1.1. It's good to fix it.

@danielkerr
Contributor

i can fix it. i know the issue.

@danielkerr danielkerr added a commit that referenced this issue Aug 16, 2015
@danielkerr danielkerr #3093 b8d1caf
@danielkerr
Contributor

this commit fixes the issue but i'm still going to move vouchers being sent to the events system

@danielkerr danielkerr closed this Aug 16, 2015
@alber5901

How can I apply this email fix to 2.0.3.1 without upgrading OC to 2.1 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment