The hook hook_commerce_cart_product_prepare should be invoked prior to adding the registration to the cart, and hook_commerce_cart_product_add afterwards. Look into commerce_cart.api.php of Drupal Commerce's core Cart module for documentation of these hooks.

However, adding a registration to the cart through the Registration Commerce 2 module will never invoke any of these hooks. This prevents custom code to prohibit another product besides a registration in the cart.

Comments

roball’s picture

The attached patch fixes the issue.

The function registration_commerce_cart_registration_add() has a lot of its code copied from Commerce core's commerce_cart_product_add() function. However, the two occurrences of rules_invoke_all() have been missed out to be copied from the original module. This patch re-adds them to the proper places. I have tested the patched module to successfully invoke both hooks on the proper events.

roball’s picture

Assigned: Unassigned » roball
Status: Active » Needs review
roball’s picture

Just wanted to note that my patch from #1 above also applies cleanly to the latest development snapshot (currently 7.x-1.0-beta1+14-dev from 2015-May-06).

  • gcb committed bac5d9f on 7.x-1.x authored by roball
    Issue #2452345 by roball: hook_commerce_cart_product_prepare and...
gcb’s picture

Assigned: roball » Unassigned
Status: Needs review » Fixed

Added in dev. Thanks for the patch!

roball’s picture

Status: Fixed » Closed (fixed)

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