1

I am getting the following error when invoking "commerce_cart_order_product_line_item_delete()" in a custom module I'm writing.

Fatal error: Call to undefined function commerce_entity_reference_delete() in /Users/[username]/Documents/Sites/[site_name]/profiles/commerce_kickstart/modules/contrib/commerce/modules/cart/commerce_cart.module on line 1268

The commerce_entity_reference_delete() function that Drupal claims it can't find resides in:

/[site]/profiles/commerce_kickstart/modules/contrib/commerce/commerce.module

Which, if I understand correctly is THE main commerce module that makes the whole shopping cart functionality work. So, my commerce module is enabled (because my shopping cart is working, and which is confirmed also on the Modules page), so why isn't commerce.module serving up the function above for me?

Aren't I allowed to call commerce_cart_order_product_line_item_delete() from a custom module?

0

This function commerce_cart_order_product_line_item_delete is in commerce_cart.module in line 1259 tnen in line 1268 call commerce_entity_reference_delete, function should be in commerce.module file line 124, check the function exist there. This is some strange if the function exist in commerce.module and return fatal error, I suggest first be sure that the function exist in code then clear cache and then try again. It is allowable call any function in any custom module and drupal not have restriction about this subject.

| improve this answer | |
0

A custom module can call any function defined from another module, if these conditions are met.

  1. If the function is defined in the module file, that module must be installed, enabled, and loaded
  2. If the function is defined in a .inc file, the module must be installed, and the file containing the function must be first loaded with module_load_include()

To expand the first point, if you are calling that function in hook_boot(), it could be too early for that, since the other module could not be loaded, yet.

In your case, commerce_entity_reference_delete() is defined in the commerce.module file, so the only reason I can think for that error is that the other module is calling commerce_entity_reference_delete() too early, when the module is not yet loaded, or Drupal didn't even complete its bootstrap, which happens with external script trying to call Drupal functions.
It could also be that the line calling commerce_entity_reference_delete() is not put inside a function call, and in this case we are back to commerce_entity_reference_delete() being called before the module file containing it is loaded.

| improve this answer | |
0

Sounds like the weight of your module is lighter than drupal_commerce (not the best starting point, I would change the module name and "reinstalling" my custom module)

So if you trying to call function that declared in another module before all modules are loaded, it will throw the above exception.

Also please have a look at: hook_module_implements_alter

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.