Fatal Design Flaw: VirtueMart Integration Plugin

10 years 4 months ago #238921 by joomlapolis.ptr
Fatal Design Flaw: VirtueMart Integration Plugin was created by joomlapolis.ptr
There is a fatal design flaw in the VirtueMart integration plugin for CBSubs.

I was having problems with new subscribers not getting their VirtueMart discounts. The new users were showing up in VM's Shoppers list, but their shopper groups were still set on "-default-" and not "Discount". After looking at the _virtuemart_userinfos table, and the error messages (when turned on in Joomla!), I have found out why.

The values in the "virtuemart_userinfo_id" field are (sample data):
1
2
4294967295
654824
9
6
174369

While their respective "virtuemart_user_id" values are (sample data):
1
2
3
5
6
9
8

From the size of the registered user-base of the site I am rebuilding, any field in any table with "user" and "id" in the name should not exceed four digits, and as you can see from the sample data, above. . . .

Sample error message:
500 - JDatabaseMySQLi::query: 1062 - Duplicate entry '4294967295' for key 'PRIMARY' SQL=INSERT INTO `j25_virtuemart_userinfos`
(`virtuemart_userinfo_id`, `virtuemart_user_id`, `address_type`, `address_type_name`, `name`, `first_name`, `middle_name`, `last_name`, `created_on`)
VALUES ('a25949590afc82aefbcccc528761c513', 1156, 'BT', '-default-', 'Public User', 'Public', '', 'User', '2013-03-12 19:23:09')

Fortunately, I have upgraded the site to CBSubs 3.0.0 (now I can debug!). The source of the error is at lines 240 and 251 of cbsubs.virtuemart.php (and possibly at lines 205 and 218, I can not answer this as I have not used VM 1.x). Simply delete these lines. As you can see in the output from a MySQL describe command, shown below, manually setting a value to virtuemart_userinfo_id is unnecessary, it is an auto_increment field!

I would like to know why you chose to set the value of the virtuemart_userinfo_id field, when it is unnecessary, and to use an MD5 hash.

Please comment.

MySQL> describe j25_virtuemart_userinfos;
+
+
+
+
+
+
+
| Field | Type | Null | Key | Default | Extra |
+
+
+
+
+
+
+
| virtuemart_userinfo_id | int(1) unsigned | NO | PRI | NULL | auto_increment |
| virtuemart_user_id | int(1) unsigned | NO | | 0 | |
| address_type | char(2) | NO | | | |
| address_type_name | char(32) | NO | | | |
| name | char(64) | YES | | NULL | |
| company | char(64) | YES | | NULL | |
| title | char(32) | YES | | NULL | |
| last_name | char(48) | YES | | NULL | |
| first_name | char(48) | YES | | NULL | |
| middle_name | char(48) | YES | | NULL | |
| phone_1 | char(32) | YES | | NULL | |
| phone_2 | char(32) | YES | | NULL | |
| fax | char(32) | YES | | NULL | |
| address_1 | char(64) | NO | | | |
| address_2 | char(64) | YES | | NULL | |
| city | char(64) | NO | | | |
| virtuemart_state_id | smallint(1) unsigned | NO | | 0 | |
| virtuemart_country_id | smallint(1) unsigned | NO | | 0 | |
| zip | char(32) | NO | | | |
| agreed | tinyint(1) | NO | | 0 | |
| created_on | datetime | NO | | 0000-00-00 00:00:00 | |
| created_by | int(11) | NO | | 0 | |
| modified_on | datetime | NO | | 0000-00-00 00:00:00 | |
| modified_by | int(11) | NO | | 0 | |
| locked_on | datetime | NO | | 0000-00-00 00:00:00 | |
| locked_by | int(11) | NO | | 0 | |
+
+
+
+
+
+
+
26 rows in set (0.01 sec)

The offending code:
237 } elseif ( $this->getVirtuemartVersion() == 2 ) {
238 $query = 'INSERT INTO ' . $_CB_database->NameQuote( '#__virtuemart_userinfos' )
239 . "\n ("
240 . $_CB_database->NameQuote( 'virtuemart_userinfo_id' ) /* This line. */
241 . ', ' . $_CB_database->NameQuote( 'virtuemart_user_id' )
242 . ', ' . $_CB_database->NameQuote( 'address_type' )
243 . ', ' . $_CB_database->NameQuote( 'address_type_name' )
244 . ', ' . $_CB_database->NameQuote( 'name' )
245 . ', ' . $_CB_database->NameQuote( 'first_name' )
246 . ', ' . $_CB_database->NameQuote( 'middle_name' )
247 . ', ' . $_CB_database->NameQuote( 'last_name' )
248 . ', ' . $_CB_database->NameQuote( 'created_on' )
249 . ')'
250 . "\n VALUES ("
251 . $_CB_database->Quote( md5( uniqid( $user->id ) ) ) /* This line, too. */
252 . ', ' . (int) $user->id
253 . ', ' . $_CB_database->Quote( $address_type )
254 . ', ' . $_CB_database->Quote( $address_name )
256 . ', ' . $_CB_database->Quote( $user->name )
257 . ', ' . $_CB_database->Quote( $user->firstname )
258 . ', ' . $_CB_database->Quote( $user->middlename )
259 . ', ' . $_CB_database->Quote( $user->lastname )
260 . ', ' . $_CB_database->Quote( date( 'Y-m-d H:i:s' ) )
261 . ')';

Joomla! stack:
Joomla! 2.5.16
VirtueMart 2.0.24c
Community Builder 1.9.1
CB Paid Subscriptions 3.0.0
CBSubs VirtueMart 1.2.3

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #238937 by krileon
This is a known issue as VM 2 suddenly changed how the ID is stored. For VM 1.x and early VM 2.x that is how the ID was generated and stored. These constant changes is why VM support is being dropped. We can not reliably maintain support for it. To workaround the issue change it from md5( uniqid( $user->id ) ) to $user->id.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.145 seconds

Facebook Twitter LinkedIn