Create a registration. Remove it from the cart. The registration still exists, with status of pending.

User decides they really do want to register and tries to add it to the cart - but they can't since the registration already exists.

I would expect removing registration from the cart to automatically cancel the registration (and I'm assuming if the registration is cancelled, the registrant would be allowed to register again.

Ideally, this would be in the code, but I'd be happy to have a reaction rule to do it.

Comments

pglatz’s picture

I tried creating a rule to do this. I was able to get the registration id, and am calling registration_delete_multiple(array($reg_id))

It deletes the registration correctly, but is displaying the wrong product name in the status message. I've traced this to a call in commerce_cart_line_item_delete_form_submit().

$line_item_wrapper->data->line_item_label contains the correct product id.

but $line_item_wrapper->data->commerce_product['und'][0]['product_id'] points to an unrelated product.

Any suggestions on a better way to do this?

asirjacques’s picture

Hi,

I've post my solution here. May be that could help you both.

Regards,

gcb’s picture

Category: Bug report » Feature request

I think deleting the registration is overzealous: an option to create a smart behavior using rules is the most commerce-y way to solve this, but I could also see simply having a couple of checkbox configuration options and hard-coding the behavior. Anyone have preferences here? Here are the behaviors I think could be available when an item is removed from a cart:

1. Do nothing to the registration. (Current behavior: sensible default)
2. Delete the registration item.
3. Change the registration item's state to a selectable option.

Does anyone see any other sensible use cases? Do any of these 3 seem unnecessary?

I have a site where 3rd parties can pay for someone's registration, and the registrations carry a lot of extra data, so you might have a situation where someone add the registration to their cart, then removes it so their employers can add it to *their* cart to pay for it. In that case we don't want to touch the registration when it is removed. Etc.

Thoughts welcome, would be nice to get an elegant solution in before a 1.0 release.

artbussy’s picture

Don't know if it's possible to have a waiting list. Owners of removed items could receive an email through Rules stating that they are placed on the waiting list for a limited period of time. Within this time limit they either confirm or ignore (leading to cancellation of the resevation).

bobojo’s picture

@Lynxas: Your code was quite helpful for my use case. I've made some modifications to protect against potential errors, so I thought I'd post my version here.

/**
 * Implements hook_commerce_cart_product_remove().
 * Check if we're removing a registration line item and delete the corresponding
 * registration so the user can sign up again without any errors.
 * @param  object $order     Commerce Order entity this item is attached to
 * @param  object $product   Commerce Product entity (REGISTRATION if reg item)
 * @param  int    $quantity  In the case of registration, number of tickets
 * @param  object $line_item Commerce Line Item entity (type = 'registration')
 * @return                   (none)
 */
function MYMODULE_commerce_cart_product_remove($order, $product, $quantity, $line_item){
  // I use an Entity Metadata Wrapper here for convenience (requires entity 
  // module), but you could also check $line_item->type or whatever the
  // equivalent property is.
  $li_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  if ($li_wrapper->getBundle() === 'registration') {
    // REGISTRATION_COMMERCE_FIELD is a constant set by Registration Commerce,
    // so this will make sure our code remains consistent if they ever change it
    $registration_id = $li_wrapper->{REGISTRATION_COMMERCE_FIELD}->raw();
    registration_delete_multiple(array($registration_id));
  }
}

EDIT: Added some comments. Also, registration_delete() doesn't exist, which seems like it could be a bit of an oversight, but that's fine. So I updated it to use registration_delete_multiple() like the original code.

MrPaulDriver’s picture

I think this is a much needed feature which ought to be coded into the module.

norwegian.blue’s picture

@bobojo
Thanks - your code was exactly what I was looking for.
I agree @MrPaulDriver - this feature should be included in the module

gcb’s picture

Status: Active » Fixed

A default rule has been added to the module to resolve this. It is disabled by default, but you can just enable the rule to get this behavior. The rule is called "Delete registration with line item". Code is here. http://cgit.drupalcode.org/registration_commerce/tree/registration_comme...

Status: Fixed » Closed (fixed)

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