Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Credit Class/Gift Voucher Can't Assign Percentage Discounts


Guest

Recommended Posts

Switched to a new server which uses PHP 5.2.17 and MySql 5.6.38 and ever since, I'm having issues with lots of things.

Yes, I'm running an old version of osCommerce - 2.2

Been able to work around most of it, but when trying to create a discount coupon with an assigned percentage - like 20% off a purchase of $25 or more - I get the following error:

1366 - Incorrect decimal value: '20%' for column 'coupon_amount' at row 1

The problem is the % mark.  I've tried adding code to the coupon_admin.php file to deal with the percentage sign, but it's not working.

I added:   $_POST['coupon_amount'] = preg_replace('/[^0-9.%]/', '', $_POST['coupon_amount']);

No luck. 

It's the only thing left to fix since the server switch - any ideas?  Thanks!

 

Link to comment
Share on other sites

I have another contribution installed called Advanced Specials which IS working when I enter a % symbol.

Looking at the code, I'm seeing different language, if you will.  The code is referencing decimals like this:

if(preg_match("/^[0-9]{1,3}([" . $currencies->currencies[DEFAULT_CURRENCY]["decimal_point"] . "][0-9]{1," . intval($currencies->currencies[DEFAULT_CURRENCY]["decimal_places"]) . "})?%$/", $discount))

The server likes that very much.

The chunk of code that's blowing up in the coupon_admin.php file looks like this:

if (substr($HTTP_POST_VARS['coupon_amount'], -1) == '%') $coupon_type='P';

Entering a % symbol blows the whole thing when creating a coupon.  Works great when applying price discounts in advanced specials, though.

Any way to rewrite the coupon code snippet above?  Perhaps something similar to the first code snippet I posted from Advanced Specials?  Decimal this, decimal that?  Am I even in the ballpark here?

Link to comment
Share on other sites

Never did figure out how to fix the code to allow a percentage symbol to be manually entered when creating a coupon.

Fixed amount has always worked since the server switch, so...

My workaround, if you will, is to do this:

I want a coupon worth 25% off a purchase of $25 or more.

I create a coupon using the amount of 25.  No percent symbol to follow as that blows up.  My coupon, at the moment, is now worth $25 off a purchase of $25 or more.

Then, i go into PHPmyadmin and select my database.  I click on Coupons and see my newly created coupon.

I select it and click Edit. 

I change the coupon_type field from type F to type P.   From fixed price to percentage.  Then I click Go.

I now have a coupon active in the site for 25% off.  Clearly shows as such in Admin, as well

PITA, but...better than nothing!

Link to comment
Share on other sites

@puggybelle, I don't know anything about Advanced Specials, but when I do a "desc coupon" in mysql, I get amount is a decimal, which means you cannot store the '%' sign in that column. I believe CCGV strips the '%' sign and store the amount in numeric value. It uses the column coupon_type 'p' to denote it's a percent off coupon. Some where along the way in the coupon admin that logic is not working right for you. Strange, it probably has nothing to do with the DB upgrade if it was working before.

I upgraded PHP and DB many times and never had any issues with CCVG. I had CCVG runnning since 2004, and I now run PHP 5.6.31 and Mysql (Percona) 5.7. OSC BS.

 

Screen Shot 2018-01-26 at 10.16.20 PM.png

Link to comment
Share on other sites

@puggybelle, I'll be damn and what do you know. I tested it and your right that your MySQL must be in some kinda strict mode. It doesn't store that '%' number anymore. I now recall I had to downgrade the MySQL engine in the config file at startup, but for other reasons. BTW, this codes should work, and just update it in your coupon_admin.php...yeah, comment that one line and replace it with what's below it should do. Good luck!

        //if (substr($coupon_amount, -1) == '%') $coupon_type='P';

        if (substr($coupon_amount, -1) == '%') {
                $coupon_type='P';
                $coupon_amount = preg_replace('/%/', '', $coupon_amount);
        }

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...