Userpoints earning fails on empty custom field

  • Posts: 13
  • Thank you received: 2
10 years 3 months ago #168646

-- url of the page with the problem -- : www.ready-to-win.com/rtw14/
-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.3
-- PHP version -- : latest

Hi,

I found a bug in the Userpoints module. When a new user is created, his user points field is not 0, but empty. If the userpoints plugin then tries to add earned points to the account, it fails. It seems that the isset function returns false, even though it should return true.

plg_hikashop_userpoints --> userpoints.php

I changed line 263 to this:

if(!isset($oldUser->user_points))
$oldUser->user_points = 0;

Now it works, but it is more a quick fix than a solution.

All the best,

Lukas

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #168649

Hi,

Thanks for the report.
It is really weird that the "user_points" are not available in the $oldUser object even if the value in NULL in the database ; the column exists so it should be present.
Can you please try to make a " var_dump($oldUser); " before the test of the field availability ?

We can't force the value if the column does not exist ; otherwise it will generate a SQL error for users having the plugin published but without the custom field configured (I know that might not append because you have to configure a plugin instance, etc ; but it's safer to check).

I will also make some test in my side on different Joomla versions.
Which mysql version do you use ?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 2
10 years 3 months ago #168681

hope this helps:

Database Version 5.1.73-1-log
Database Collation utf8_general_ci
PHP Version 5.3.29
Web Server Apache/2.2.16 (Debian) DAV/2 mod_ssl/2.2.16 OpenSSL/0.9.8o

stdClass::__set_state(array( 'user_id' => '8', 'user_cms_id' => '813', 'user_email' => 'This email address is being protected from spambots. You need JavaScript enabled to view it.', 'user_partner_email' => '', 'user_params' => stdClass::__set_state(array( )), 'user_partner_id' => '0', 'user_partner_price' => '0.00000', 'user_partner_paid' => '0', 'user_created_ip' => '212.197.132.162', 'user_unpaid_amount' => '0.00000', 'user_partner_currency_id' => '0', 'user_created' => '1408859869', 'user_currency_id' => '0', 'user_partner_activated' => '0', 'user_points' => NULL, 'id' => '813', 'name' => 'Lukas Erhart', 'username' => 'lerhart2', 'email' => 'This email address is being protected from spambots. You need JavaScript enabled to view it.', 'password' => '$2y$10$f/liRjSTG7eFJp1O9shr.ep9rNe5Bo2voSpffroUwEE/rd2/IPUBC', 'block' => '0', 'sendEmail' => '0', 'registerDate' => '2014-08-24 05:57:49', 'lastvisitDate' => '2014-08-24 05:58:06', 'activation' => '', 'params' => '{"site_language":"en-GB","language":"en-GB"}', 'lastResetTime' => '0000-00-00 00:00:00', 'resetCount' => '0', 'otpKey' => '', 'otep' => '', 'requireReset' => '0', ))


best regards,

lukas

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 2
10 years 3 months ago #168682

PHP docs for isset:

Determine if a variable is set and is not NULL.
If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

I'd recommend the following:

if(!isset($oldUser->user_points))
		{
			if (is_null($oldUser->user_points))
			{
				$oldUser->user_points = 0;
			} else
			{
				return false;
			}
		}

The following user(s) said Thank You: Jerome

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 months ago #168700

Hi,

is_null will create a "notice" if the "user_points" really does not exists.
So I will prefer something like

if(!isset($oldUser->user_points) && !in_array('user_points', get_objectt_vars($oldUser)))
   return false;
Or
if(!property_exists($oldUser, 'user_points'))
   return false;
Depending if we want to keep the PHP4 compatibility for Joomla 1.5 users.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum