tastyigniter / TastyIgniter

:fire: Powerful, yet easy to use, open-source online ordering, table reservation and management system for restaurants
https://tastyigniter.com
MIT License
3.04k stars 997 forks source link

Applying a coupon of 100% or more than order total causes issues and more coupon woes #388

Closed brendanwex closed 4 years ago

brendanwex commented 4 years ago

Expected behavior: I was hoping it would let me checkout with a 100% coupon.
Removing a coupon from the cart only removes it from the DOM, when you proceed to checkout it is back again.

Actual behavior: SQL error on attempted checkout because there is no payment processor listed

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'payment' cannot be null (SQL: insert into ti_orders (first_name, last_name, email, telephone, customer_id, location_id, order_type, order_date, order_time, payment, total_items, cart, order_total, ip_address, comment, address_id, hash, user_agent, date_modified, date_added) values (aaa, aaa, aaa@aaaa.com, aaa, ?, 1, delivery, 2020-05-28 00:00:00, 08:13, ?, 1, O:30:"Igniter\Flame\Cart\CartContent":1:{s:8:"items";a:1:{s:32:"370d08585360f5c568b18d1f2e4ca1df";O:27:"Igniter\Flame\Cart\CartItem":8:{s:5:"rowId";s:32:"370d08585360f5c568b18d1f2e4ca1df";s:2:"id";i:2;s:3:"qty";s:1:"1";s:4:"name";s:10:"SCOTCH EGG";s:5:"price";d:2;s:7:"comment";s:0:"";s:7:"options";O:34:"Igniter\Flame\Cart\CartItemOptions":1:{s:8:"items";a:0:{}}s:18:"*associatedModel";s:31:"Igniter\Cart\Models\Menus_model";}}}, 0, fe80::195f:a7aa:e95c:598b, aaa, 2, 990ef4b2e63a976dc472a0d19920cb8b, Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0, 2020-05-28 07:58:20, 2020-05-28 07:58:20))

Reproduce steps:

Version: 3.0.4-beta.20.1

Additional Information: I could later the table to allow null value on the payment row, but I am thinking there may be more to this than a simple SQL change.

I was planning on extending the API to allow creating of Coupons via a WooCommerce store so they could act like a gift certificate, once order was completed if any value remained on the certificate / coupon i would be update the total to the new balance (if any)

sampoyigi commented 4 years ago

I'm unable to reproduce the issue. The expected behaviour is the coupon form displays after an item has been added to cart. Adding an item with 0.00 price to cart returns an error message 'can't apply on order below 0.00' which is also the expected behaviour.

brendanwex commented 4 years ago

Thanks, OK I understand the system does not allow checkout on 0.00 amounts. Do you think it is possible to allow 0.00 checkouts by simply allowing the payment column to be null or would a better solution be if i try to create a new payment provider called "coupon" that only activates if the balance is 0.00 and that sets the payment column as "coupon", does that sound plausible?

Regarding other issue with coupon being removed from DOM and coming back at checkout. It seems as if it is being stored in the session and the AJAX request is not removing it completely.

  1. On the menu screen, add an item to the cart.
  2. Add the coupon code and apply it.
  3. Remove the coupon code.
  4. Proceed to checkout.
  5. The coupon is back again.
sampoyigi commented 4 years ago

So with the current setup, your customers can apply a 100% coupon discount on the cart total (provided they already have an item with price > 0 in cart) to allow a no payment checkout. So if you want to allow checkout without payment you can create a 100% discount coupon to apply on the cart.

Ok just read the initial post again, for the database error setting the payment field to an empty string should work.

Issue with removing coupon has been fixed here tastyigniter/flame@cf923d6

brendanwex commented 4 years ago

Thanks Sam