Topic
  • 4 replies
  • Latest Post - ‏2013-07-10T16:40:43Z by jpurdum
Jacobo_Adolfo
Jacobo_Adolfo
28 Posts

Pinned topic Locking an order

‏2013-07-09T09:13:31Z |

Hi.

I need to lock an order by using the orderid, to disallow the shopper to modify the order (add new items, remove items...)

I try to use the OrderLockingHelper, but it seems that is not working:

                OrderLockingHelper lockingHelper = new OrderLockingHelper(getCommandContext().getActivityToken());
                logger.info("-->"+lockingHelper.isLocked(new Long(22001)));
                lockingHelper.checkLock(new Long(22001));
                logger.info("-->"+lockingHelper.isLocked(new Long(22001)));
                lockingHelper.checkAndCSRLock(new Long(22001));
                logger.info("-->"+lockingHelper.isLocked(new Long(22001)));

In the three lines 'logger...' the resutl is always false, it seems that the order is not being locked.

What I am doing wrong???

Thank you so much.

  • Raj.S
    Raj.S
    523 Posts

    Re: Locking an order

    ‏2013-07-09T17:14:16Z  

    I think the methods you are using are for the CSR users. Have you tried

                   lockingHelper.lock(orderId);   -- locks the order and throws an exception if already locked.

     

    Rgds, Raj.

  • Jacobo_Adolfo
    Jacobo_Adolfo
    28 Posts

    Re: Locking an order

    ‏2013-07-10T06:10:44Z  
    • Raj.S
    • ‏2013-07-09T17:14:16Z

    I think the methods you are using are for the CSR users. Have you tried

                   lockingHelper.lock(orderId);   -- locks the order and throws an exception if already locked.

     

    Rgds, Raj.

    Hi Raj.

    I've tried the method you said, but i don't see if the order is locked. It does not seem that:

                    lockingHelper.lock(new Long(22001));
                    logger.info("-->"+lockingHelper.isLocked(new Long(22001)));

    isLocked return false, no exception is thrown.

     

    Thanks.

  • Vani Mittal
    Vani Mittal
    40 Posts

    Re: Locking an order

    ‏2013-07-10T06:47:12Z  

    Hi Raj.

    I've tried the method you said, but i don't see if the order is locked. It does not seem that:

                    lockingHelper.lock(new Long(22001));
                    logger.info("-->"+lockingHelper.isLocked(new Long(22001)));

    isLocked return false, no exception is thrown.

     

    Thanks.

    If you want to lock an order temporarily so that a CSR can edit it, you can use the AdvancedOrderEditBeginCmd. Once the editing is complete, call the AdvancedOrderEditEndCmd to release the lock.

  • jpurdum
    jpurdum
    7 Posts

    Re: Locking an order

    ‏2013-07-10T16:40:43Z  

    When are you attempting to lock the order?  If you're trying to lock the order at the end of a transaction such as submitting the order, you may need to commit the existing transaction.  I would have to look at how OrderLockingHelper handles the order to be sure.  As a quick and dirty test try the following:

    //Ensure you've imported the following:
    //import com.ibm.commerce.server.TransactionHandle;
    //import com.ibm.commerce.server.TransactionManager;
    TransactionHandle transaction = null;
     
    try {
    //Commit the existing transaction
    if (TransactionManager.isTransactionActive()) {
    TransactionManager.commit();
    }
    //Create new transaction for locking the order
    transaction = TransactionManager.begin();
     
    //...Code to lock the order
     
    //Commmit the current transaction
    TransactionManager.commit(transaction);
    } catch (Exception ex) {
    //Check to see if this is a rollback exception from the original commit
    if ((ex instanceof RollbackException)) {
    throw new ECSystemException(ECMessage._ERR_ROLLBACK_EXCEPTION, CLASSNAME, mn, new Object[] {ex.getMessage()}, ex);
    } else {
    //Check transaction
    if (transaction != null) {
    TransactionManager.rollback(transaction);
    }
    //...Handle other exception instances if necessary
    }
    } finally {
    //Check to see if a transaction is active and create if one isn't active.  
    //The web controller will try to commit the current transaction and will error out if another transaction isn't started.
    if (!TransactionManager.isTransactionActive()) {
    TransactionManager.begin();
    }
    }

         This will probably do the trick.  The code may have some compile errors as I wrote this off the top of my head.  Let me know.

     

    JP