This seems not to work as expected on a fresh install (from ec_product.install):

$ptype = ec_product_ptypes_get('type', 'tangible');
ec_product_feature_enable($ptype, 'shippable');

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Soren Jones’s picture

Version: 6.x-4.0-rc13 » 6.x-4.x-dev
Status: Active » Needs work

The issue seems to be with calling drupal_write_record from hook_enable (via ec_product_feature_save and ec_product_feature_enable). http://api.drupal.org/api/function/drupal_write_record/6#comment-2273

I've found two solutions that work.
1) Substitute db_query for lines 105 and 106 in ec_product_enable.

db_query("INSERT INTO {ec_product_features} (ptype, ftype, data, weight) VALUES ('tangible', 'shippable', NULL, '0')");

2) Add drupal_get_schema to ec_product_enable before line 105 (or somewhere in ec_product_feature_enable).

drupal_get_schema(NULL, TRUE); 

I don't know which is better (e.g., Is it risky to call drupal_get_schema from ec_product_enable if people are enabling multiple modules?).
Or if there is another "best" option.
Any thoughts?

Xen’s picture

I'd go with db_query. It's the safe option.

Soren Jones’s picture

Status: Needs work » Needs review
FileSize
869 bytes

Xen, Thank you. Attached for review.

Xen’s picture

Looks good to me, but it's Gordon that got the final say.

gordon’s picture

Status: Needs review » Needs work
+++ ec_product/ec_product.install	12 Jul 2010 11:27:29 -0000
@@ -102,8 +102,7 @@ function ec_product_enable() {
-    $ptype = ec_product_get_types('type', 'tangible');
-    ec_product_feature_enable($ptype, 'shippable');
+    db_query("INSERT INTO {ec_product_features} (ptype, ftype, data, weight) VALUES ('tangible', 'shippable', NULL, '0')");
     _ec_product_create_node_type();

I really don't like this esp. since if changes are made to ec_product_feature_enable() it is likely to break the initial install.

How because of your explanation I agree that inserting this directly is the safest option.

Just so this doesn't explanation doesn't get lost can you please add this a reference to this issue and the explantion to the in line documentation for ec_product_feature_enable() so if anything additional processing is added in future people should see it and replicate the code.

Also what would be even better is to add an assertion to one of the products tests to make sure that the tangible product has the shippable feature attached.

Thanks.

Powered by Dreditor.

Soren Jones’s picture

So would it be best to get rid of ec_product_feature_enable() all together (remove it from ec_product) and use the direct insert in ec_product_update_5402() as well?

Will do on the reference and will take a shot at adding an assertion to one of product test.

Thanks for the feedback.