I'm running a subscription site and using Commerce License Role to allow users to purchase a user role which provides access to the system.

On expiry, emails are sent to the users reminding them that they should renew their subscription. What I want to happen is that the system can find any existing licenses and renew them for the required amount of time rather then issuing a new license.

I've been keeping an eye on https://www.drupal.org/node/2193305 but that thread has gone down the route of changing the dates on a newly purchased license so it extends the existing membership. I want to explore the use case above and thought that it deserves a thread of it's won distinct from https://www.drupal.org/node/2193305.

My initial problem is, I have no idea where to even start. It seems that a license is created when the product is added to the cart, and the status of that license is changed when payment is confirmed.

Is the correct approach here to find the existing license when the product is added, then associate the existing license with the order? Is there an issue with that license then being associated with two orders?

Would we also need further logic when payment is confirmed to decide when the expiry date is, so to call renew() on the existing license with the purchased amount of time to add to the existing license.

Essentially I don't want any new license created at all and any guidance on where I should look would be very much appreciated.

Comments

darksnow created an issue. See original summary.

garphy’s picture

The problem is that a License entity is automatically created and saved when the corresponding product is added to cart. We would have to trash that "temporary" license when renewing the existing one.

darksnow’s picture

Thanks for the reply. I realise that this is an issue but how hard would it be to trash the license? What are the implications? Most importantly, how can it be done?

For my use case, by the time somebody gets to checkout they must be logged in, but not when the temporary license is created as you describe above. As such I think what we're looking at is some way to remove the temporary license and replace it, in the current order, with the old one before the "Activate License" rule would fire. That way the existing system would carry on with the order unaware of the change.

Is Rules the correct way to do this? Some custom code added as a rule when the sale is completed?

farse’s picture

I am looking on how to do this as well. Are the knock-on affects far and wide if this route is taken?

tomtech’s picture

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.