I've been pondering how to handle the case where a new order is made to renew a license.

On the one hand, we want the new order to have the same values as the original, and hold an order item for the license product. On the other hand, we don't want our code that creates a new license for this product to kick in!

Given this is going to be an automatic order, it seems to me that the simplest thing is to require whoever creates the order to set the existing license to renew on the order item when they add it to the order.

LicenseOrderSyncSubscriber should then pick up on this, and instead of creating a new license, renew the one it finds.

Comments

joachim created an issue. See original summary.

joachim’s picture

Status: Active » Closed (outdated)

This is obsolete -- see #2908031: change LicenseOrderSyncSubscriber::getOrderItemsWithLicensedProducts() to detect order items, not products.

In fact, if a license is already present on an order item, the sync process should just carry on as if it had just created it. This allows for programmatic creation of licenses to put automatically into the cart, such as a 'buy access to this file' link.

subhojit777’s picture

Hey @joachim, we have this requirement in one of our project. After reading your comments on this issue, and checking LicenseOrderSyncSubscriber, this is what I understand is the way to implement license renewal using a new order.

  1. User visits the license product page
  2. He sees that his license is expired (or about to expire), and he opts for license renewal
  3. He clicks "Add to cart"
  4. The license order item that was previously used for purchasing the license is load-ed, and attached to a new order
  5. User proceeds with the renewal process, and pays and completes the order. LicenseOrderSyncSubscriber takes care of renewing the license

Could you please confirm whether I am right. If yes, then I believe points 2 and 4 have to be written in a custom module or something.

subhojit777’s picture

I followed #3 and they are working. One important point here is - you would have to add a submit callback in `add to cart` form, that is going to attach the expired license to the newly created order item. And LicenseOrderSyncSubscriber will take care of everything.