CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
SAP Subscription Billing supports you in your subscription business, from the definition of products and rate plans through orchestration and subscription management to billing. Furthermore, it enables you to manage usage and customer data. When integrated with SAP Commerce or SAP Commerce Cloud, you can leverage these powerful capabilities to deliver exceptional customer experience through your e-commerce platform.


 

The 2005 release of SAP Commerce and SAP Commerce Cloud introduces an enhanced data model to the existing integration setup. In the integration with SAP Subscription Billing specifically, this may disrupt the replication processes as the existing products are stored in the outdated data model. After the upgrade, as an administrator, you would want to update all the existing subscription products in your SAP Commerce or SAP Commerce Cloud database to the new data model. Read on to see how this can be done in just a few steps.

Prerequisites

Before getting started, ensure that:




  • You are running SAP Commerce or SAP Commerce Cloud version 2005 or higher.

  • You have successfully set up and integrated with SAP Subscription Billing.

  • You are an administrator for SAP Commerce or SAP Commerce Cloud.


Procedure

Follow these steps to update the subscription product data model:

  1. Log in to Hybris Administration Console.

  2. Go to Console > Scripting Language and ensure that Script type is Groovy.

  3. Copy and paste the following migration script in the editor:
    import de.hybris.platform.tx.Transaction
    import de.hybris.platform.tx.TransactionBody
    import de.hybris.platform.core.Registry
    import de.hybris.platform.core.TenantAwareThreadFactory
    import de.hybris.platform.commerceservices.impersonation.ImpersonationService
    import de.hybris.platform.commerceservices.impersonation.ImpersonationContext
    import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
    import java.text.SimpleDateFormat
    import java.util.Date;
    import org.codehaus.groovy.runtime.*;
    import java.util.concurrent.Executors
    import java.util.concurrent.TimeUnit;
    /*******************************/
    /** Core **/
    /*******************************/
    def getBean(String name) {
    return spring.getBean(name)
    }
    /**
    * Builder class to execute closure in Transaction.
    */
    class TransactionExecutor {
    /**
    * Build an TransactionExecutor.
    */
    TransactionExecutor() {}
    /**
    * Execute the specified closure in a transaction.
    */
    def execute(Closure execution) {
    def currentTx = Transaction.current()
    return currentTx.execute(new TransactionBody() {
    public Object execute() throws Exception {
    return execution()
    }
    })
    }
    }
    TransactionExecutor.metaClass.getBean = {name ->
    spring.getBean(name)
    }
    flexibleSearchService = spring.getBean("flexibleSearchService")
    modelService = spring.getBean("modelService")
    def date = new Date()
    sdf = new SimpleDateFormat("yyyy-MM-dd")
    currentDate = sdf.format(date)
    def query = "select {sp:pk} " + "from { " + "SubscriptionPricePlan as sp }"+
    "where {sp:startTime} <= ?startTime and {sp:endTime} >= ?endTime";
    def params = [startTime: currentDate, endTime: currentDate]
    def subscriptionPricePlanList = flexibleSearchService.search(query,params).result
    print "Current Date : " + currentDate + "\n"
    def executorService = Executors.newFixedThreadPool(10, new TenantAwareThreadFactory(Registry.getCurrentTenant()))
    try {
    if(subscriptionPricePlanList != null){
    subscriptionPricePlanList.each {entry ->
    if (sdf.format(entry.getStartTime()) <= currentDate && currentDate <= sdf.format(entry.getEndTime())) {
    entry.getOneTimeChargeEntries().each {oneTime ->
    if (oneTime.getSubscriptionBillingId() == null) {
    print "Start Time :" + sdf.format(entry.getStartTime())
    print " \t End Time :" + sdf.format(entry.getEndTime())
    print " Removing" + entry.getPricePlanId()
    print "\n"
    executorService.execute(new Runnable() {
    public void run() {
    def transactionExecutor = new TransactionExecutor()
    transactionExecutor.execute() {
    modelService.removeAll(entry)
    }
    }
    })

    }
    }
    }
    }
    }
    } finally {
    executorService.shutdown()
    executorService.awaitTermination(1, TimeUnit.HOURS)
    }


  4. Choose Execute and wait for the script to run. You can verify successful completion on the Results tab.


That's it! All subscription products in your SAP Commerce or SAP Commerce Cloud database are updated to the new data model, and you are good to go.
1 Comment