| Project: | Ubercart Contributions |
| Component: | Code |
| Category: | |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
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 25The 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 = 27Ah, 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.



