Great module, I like where this is going. After enabling it shows a blank page with this error:

Warning: Creating default object from empty value in _entity_defaults_rebuild() (line 876 of /Users/BW/Desktop/eddie-flores-2/sites/all/modules/contrib/entity/entity.module).
PDOException: SQLSTATE[HY000]: General error: 1364 Field 'plugin' doesn't have a default value: INSERT INTO {rules_config} (name, status, module) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => course_commerce_enrollments [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => course_commerce ) in drupal_write_record() (line 7239 of /Users/BW/Desktop/eddie-flores-2/includes/common.inc).

I press the back button and the see that the module is still enabled regardless of the message, however it doesn't seem to work 100% smoothly. Any suggestions? Thanks!

Comments

Neograph734’s picture

Try installing the Commerce Search API module, then clear cache and run cron and see if it made a difference. No settings on search api required for this.

DigitalFrontiersMedia’s picture

Status: Active » Needs review

commerce_search_api has been added as a dependency to allow the Rules to work as expected out of the box. Please uninstall/re-install with the latest commit to see if this issue is now resolved.

Neograph734’s picture

Title: Error when enabling module » Error when enabling and uninstalling module
Status: Needs review » Needs work

The module enabled fine, but could not uninstall. So I altered the ticket a bit.

There is a fatal error for the non-existing function feature-delete(). (I don't have features installed.) Since there is also no feature involved during installation, I guess it can be removed from line 197 of the .install file.

DigitalFrontiersMedia’s picture

Status: Needs work » Needs review

Adjusted. Re-test?

Neograph734’s picture

Gimme a sec, I need to test the rest as well ;)

Neograph734’s picture

Priority: Normal » Minor
Status: Needs review » Needs work

No more fatal errors, so the module uninstalls... But there is a problem with the product / node deletion code still.

The query on line 172 - 175 selects the product_id of the commerce course products. And I guess it should delete the corresponding nodes, which it luckily failed to do, as the nodes have another id then the product_id.

The problem lies in the fact that the query does not return a nid as expected on line 179.

So I suppose you should find the node that corresponds to the product id, by joining field_data_commerce_product and commerce_line_item tables. The node id is in the data string of that table. Then by deleting the node, I suppose commerce and inline entity form will remove the other traces.

So not a major game breaker, but if you want to clean up I guess this is the only way.

DigitalFrontiersMedia’s picture

Yes, I had just looked and come to the same conclusion. I had borrowed some code and hadn't really inspected it to realize it wasn't actually pulling the nids for Courses referencing the standard_course product type.

I'll take another stab at that. Thanks.

DigitalFrontiersMedia’s picture

Status: Needs work » Needs review

I ended up joining field_data_field_product with commerce_product instead since it didn't seem appropriate to base it off of commerce_line_item which would only apply after an order had been created including a standard_course product.

I also added a db_delete to get rid of any orphaned course_product entries of type standard_course.

Give this commit a go and let me know how it goes. Thanks again!

Neograph734’s picture

Status: Needs review » Needs work

I used it, but then came to the conclusion that there was still a product in my cart. Drupal tried to load the non-existing product, resulting in more errors.

So I guess that the product should not be deleted but disabled (it can no longer be purchased, but old references to it remain intact). After that it should be good to go.

DigitalFrontiersMedia’s picture

I'm not sure if we really need to worry about cleaning up items left in carts affected by uninstalling site functionality, although we could cycle through items in the cart and use commerce_cart_order_product_line_item_delete to remove any that apply. But you bring up something I hadn't considered at all which is the rather draconian data integrity constraints that Drupal Commerce imposes in general. Drupal Commerce will prevent deleting products that are referenced in existing orders, etc. I'm not sure if the appropriate hooks are called in the clean up processes I'm using for Drupal Commerce to police those attempts. I think so, but it should be tested for sure.

We should do a few tests on uninstallation effects on existing orders. I'll look at adding something to clean-up the cart. Unless you think disabling the products instead of deleting would still be better. If so, how do I "disable" a product?

Neograph734’s picture

It is not just the carts, but the entire order history I guess. Orders remain visible in the person's account and the system. And those orders (line-items) refer to the products. Deleting the products would break all these displays. (If you try to delete a product through the interface, you will have to remove all orders containing a product, before the actual product can be deleted as well.)

Since deleting orders would mean altering the order history of people, which is undesired. But the purchasing of new products should be prevented.

Disabling a product is as easy as changing it's status from 1 to 0 on the commerce_products table. It basically behaves the same as deleting the product, but keeping the references intact. It can no longer be displayed or purchased and the cart system gracefully removes from every open cart without errors.

DigitalFrontiersMedia’s picture

Status: Needs work » Needs review

Okay, I've committed a few changes that I think work nicely. I've added two clean-up paths on uninstall.

First, I assume that Drupal Commerce will correctly prevent deletion of Course nodes that reference standard_course products if such products are already included in existing orders. If you try to uninstall and you have Course nodes that reference standard_course products, then the module will simply disable all standard_course products (and their revisions) and leave it to the user to decide if they wish to police any existing order records which might contain standard_course products. As @Neograph734 astutely observed, simply disabling the standard_course products allows the shopping cart to refresh gracefully with no errors.

However, if one is allowed to (and does) delete all Course nodes that reference standard_course products (or removes any such references), then there is no data integrity required to be preserved and there's no reason the module shouldn't cleanly remove all traces (fields, product types, etc.), which it now does. However, because it's possible that one could have a standard_course product in their shopping cart from when the Course nodes/products were available, the module searches all incomplete orders/carts and removes any standard_course product line items from them since we are completely deleting the product data and don't want any bad references in there. It then re-saves and refreshes all of these carts so they should show cleanly as expected without standard_course products or errors.

Please review. Thanks!

Neograph734’s picture

Sounds like a well thought out approach. I'll give it a spin next week.

Neograph734’s picture

Status: Needs review » Fixed

I've encounted no additional problems. So I suppose this has all been resolved.

Setting this to fixed as the commit has already been pushed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.