Major bugs in Product Features (Role assignment).

Project:Ubercart Contributions
Component:Code
Category:
Priority:normal
Assigned:Unassigned
Status:active
Description
Project: 
Ubercart

I inserted a recurring fee feature into product with id 102:
Recurring fee amount: $30
Initial charge: 0 days
Regular interval: 1 days

The new product feature does not show up.

I did a mysql dump before and after, and here's what the diff shows for `uc_product_features`:

BEFORE:
(25,101,'role','<strong>SKU:</strong> Any<br/><strong>Role:</strong> [-] Crib \'08<br/><strong>Expiration:</strong> 1 day(s)<br/><strong>Shippable:</strong> No<br/><strong>Multiply by Quantity:</strong> Yes');

AFTER:
(25,101,'role','When this product is purchased, add a fee for $30.00 charged first after 0 days and every 1 days after that 99 times.');

Instead of actually inserting the recurring fee, this went to the previous product (id 101), and replaced the description of a role assignment feature that I entered.

Also, this was added to `uc_recurring_products`:

(25,'','30.00','0 days','1 days',100);

It seems like this should add the recurring payment feature, but it does not show up. Maybe it needs the first part in place to work correctly?

In uc_product.module, there's a function that is responsible for doing inserts and updates on `uc_product_features` - uc_product_feature_save($data).

It first attempts to update an existing row:

db_query("UPDATE {uc_product_features} SET description = '%s' WHERE pfid = %d", $data['description'], intval($data['pfid']));

... and then inserts a new one if there are no affected rows by the above query.

So it must be that somehow intval($data['pfid']) is not passed down correctly, and it ends up with the pfid of the previous inserted product feature.

in uc_recurring.module, there a function uc_recurring_feature_form_submit($form_id, $form_values) that at the end calls uc_product_feature_save().

The first few lines of that function (with extra drupal message calls):

drupal_set_message($form_values['pfid']); // returns 0
  if (empty($form_values['pfid'])) {
    $fee['pfid'] = db_next_id('{uc_product_features}_pfid');
  }
  else {
    $fee['pfid'] = $form_values['pfid'];
  }
drupal_set_message($fee['pfid']); // returns 25

The last record in `uc_product_features` already has pfid of 25.

Somehow the db_next_id doesn't return the next id, instead using the last one.

Looking in the sequences table, the sequence seems to be one behind: 'uc_product_features_pfid',24

Changing the sequence to 25 fixed the problem for product 102, and I'm able to add features without a problem, but when I create a new product, the same problem appears again.

Seems like something is up with the sequence setting.

So starting over:

uc_product_features.pfid (last) = 25
sequences: uc_product_features_pfid = 24
> Changed the sequence to 25
> Added recurring feature to product 102
Shows up fine
sequences: uc_product_features_pfid = 26
uc_product_features.pfid (last) = 26
> Added a new role assignment feature to product 102
uc_product_features.pfid (last) = 28
sequences: uc_product_features_pfid = 27

Ah, here we go. It's actually the role assignment feature that jumps one extra that causes the problem.

In uc_roles.module, there a function uc_roles_feature_form_submit, and there's a line in it:

$pfid = db_next_id('{uc_product_features}_pfid') + 1;

Is that done on purpose or is it a mistake to add that extra 1?

Thanks,
Andrey.

Version: 
Ubercart 1.3
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Major bugs in Product Features (Role assignment).

Andrey... you're awesome. That's definitely a mistake - not sure why it was done that way, but I suppose the developer just didn't grok the purpose of that function. I'd like to make the change right away, but I'll need to see some testing... any way I can get you to post back after removing that +1 on a test site to let me know if it clears up the issue without any adverse side effects?

mr.andrey's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 08/12/2008
Juice: 153
Re: Re: Major bugs in Product Features (Role assignment).
Assigned to:Ryan» mr.andrey

Yep, just reset the sequence to the correct number, tried a bunch of times adding multiple features for multiple products, and all seems to work well with the change.

A.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Major bugs in Product Features (Role assignment).
Assigned to:mr.andrey» Ryan

Was resetting the sequence mandatory? i.e., do I need to include an update func in the install file for this change?

mr.andrey's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 08/12/2008
Juice: 153
Re: Re: Re: Re: Major bugs in Product Features (Role assignment)
Assigned to:Ryan» mr.andrey

It's only mandatory if someone has been adding products with role features. The pfid jumps two while sequence jumps one. As an update I would get the last pfid, compare it with sequence pfid, and if it's greater, update the sequence accordingly.

A.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Re: Major bugs in Product Features (Role assignm
Assigned to:mr.andrey» Ryan

Sounds good... a single UPDATE query should take care of that. I'm bookmarking this and will try to commit a fix in the AM. Thanks again for all your help here! Cool

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Re: Re: Major bugs in Product Features (Role ass

Ok.. fixed this in both the roles module and file downloads module. Added necessary update functions. Permanent fix will be in the 1.4 release and is available in Bzr now. Smiling