Zen Cart Logo
Forums / Bug Reports / Possible bug during coupon creation

Possible bug during coupon creation

Views: 8,215

Results 1 to 6 of 6
21 May 2019, 14:48
#1
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Possible bug during coupon creation

Clean installation of zencart 1.5.6a.
I'm getting an error while creating a coupon for free shipping only. Discount coupons for certain amount or percentage discount can be created just fine.

Blank page with the following error displays after confirmation
WARNING: An Error occurred, please refresh the page and try again.If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you left no blank fields.

I've tried filling in all fields and I get the same error.

Log file
[B][21-May-2019 10:41:29 America/Detroit] Request URI: /... ADMIN .../coupon_admin.php?action=update_confirm&oldaction=new&cid=1&page=1, IP address: 76.112.20.152
#1 trigger_error() called at [/... CATALOG .../includes/classes/db/mysql/query_factory.php:171]
#2 queryFactory->show_error() called at [/... CATALOG .../includes/classes/db/mysql/query_factory.php:143]
#3 queryFactory->set_error() called at [/... CATALOG .../includes/classes/db/mysql/query_factory.php:270]
#4 queryFactory->Execute() called at [/... ADMIN .../includes/functions/database.php:51]
#5 zen_db_perform() called at [/... ADMIN .../coupon_admin.php:445]
--> PHP Fatal error: 1366:Incorrect decimal value: '' for column xxxxx.coupons.coupon_amount at row 1 :: insert into coupons (coupon_code, coupon_amount, coupon_product_count, coupon_type, uses_per_coupon, uses_per_user, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_start_date, coupon_expire_date, date_created, date_modified, coupon_zone_restriction, coupon_calc_base, coupon_order_limit, coupon_is_valid_for_sales, coupon_active) values ('FREESHIPPING', '', '0', 'S', '100000000', '100000000', '100', '', '', '2019-05-21', '2020-05-21', now(), now(), '5', '0', '0', '1', 'Y') ==> (as called by) /... ADMIN .../includes/functions/database.php on line 51 <== in /... CATALOG .../includes/classes/db/mysql/query_factory.php on line 171.

Any idea what could be happening??

21 May 2019, 15:14
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Possible bug during coupon creation

An amount of "nothing" is not being stored/converted to a value of 0. Instead it is being attempted to be stored as a string of empty quotes. The database does not like trying to change data types.

Would recommend at line 409 of admin/coupon_admin.php
to change: ```
zen_db_prepare_input($_POST['coupon_amount']),

To:

convertToFloat($_POST['coupon_amount']),


This may clear the single error/issue, but there may be another further down the line.
21 May 2019, 16:16
#4
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Possible bug during coupon creation

Thank you for the help DrByte.

In my version of that file admin/coupon_admin.php I have this line of code

      if ( ($_POST['back_x']) || ($_POST['back_y']) ) {
        $_GET['action'] = 'new';
      } else {

instead of the one in the link

      if ( (!empty($_POST['back_x'])) || (!empty($_POST['back_y'])) ) {
        $_GET['action'] = 'new';
      } else {

I'm wondering if I should replace that line of code too.

22 May 2019, 10:36
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Possible bug during coupon creation

mvstudio:

Thank you for the help DrByte.

In my version of that file admin/coupon_admin.php I have this line of code

  if ( ($_POST['back_x']) || ($_POST['back_y']) ) {
    $_GET['action'] = 'new';
  } else {
> 
> instead of the one in the link
> 
> ```php
      if ( (!empty($_POST['back_x'])) || (!empty($_POST['back_y'])) ) {
        $_GET['action'] = 'new';
      } else {

I'm wondering if I should replace that line of code too.
@mvstudio, I'd go ahead and make that change as well. Its purpose is to provide the same processing, but checking firs tto see that the variables exist (so your store doesn't trigger multiple PHP warnings for more recent PHP versions).

20 Jun 2019, 15:38
#6
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Possible bug during coupon creation

Thank you Lat9! =)