I need to know more on the back end flow, when a user adds an item to cart as a guest and the logs in using his valid credentials. The orderId created for the guest gets migrated to the registered user's id. Could someone please explain how this is handled ? Details of the commands and DB tables would be helpful.

I did read about a MigrateUserEntries Command but I am not sure if that is the correct one.

Thanks in advance.

4

There are 4 answers

0
Steve McDuff On

When a guest user logs in, his cart gets merged with the cart of the registered user account.

This impacts the tables related to order and order items.

You can look at the documentation of OrderCopy for more details.

0
Abed Yaseen On

First, some review about User lifecycle in WCS commerce : 1- user visited the site as generic user with USER ID = -1002 2- when user add any item to his shopping cart , WCS create an OrderId and assign it to new USER ID created and user called "guest" in this case (both #1 and #2) have userType=G 3- when user log in using login form it is by default attached to LogonCmd in struts configuration , and if you decompile that controller command you will see that it is calling MigrateUserEntriesCmd task command which responsible for migrating Addresses, Current Orders, Interest Items, Order Items, Orders, and Order templates. the new orderID that is used is the Registered OrderId .

I suggest you use decompiler installed to your RAD so you can decompile IBM classes for better understanding of the logic and then customize your code as IBM best practice (extending commands .. etc ) I use JAD eclipse plugin for decompilation .

you can further read (references): http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.admin.doc%2Fconcepts%2Fcmsmembers.htm&resultof%3D%2522%2555%2553%2545%2552%2553%2522%2520%2522%2575%2573%2565%2572%2522%2520

http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.api.doc%2Fcom%2Fibm%2Fcommerce%2Fsecurity%2Fcommands%2FMigrateUserEntriesCmdImpl.html

Thanks Abed

0
user3686158 On

But the Trick here is :-

public class MigrateUserEntriesCmdImpl
extends TaskCommandImpl
implements MigrateUserEntriesCmd

This task command is used to migrate resources owned by one user to another. The mandatory resources that are migrated are Addresses, Current Orders, Interest Items, Order Items, Orders, and Order templates.

By default, this command will not merge the shopping cart for the 2 users, but it can be configured to do so by:

a) Setting the mergeCart flag in the request property in the command context to true.

OR:

b) Setting MemberSubSystem/MergeCartsAtAuthentication/enabled in the wc-server.xml to true. The mergeCart flag in the request property will take higher priority.

Before executing this task command the following sets should be performed:

setOldUser() -->getOldUser()

This method retrieves the old user whose resources are to be migrated to the new user.

setNewUser() -->getNewUser()

This method retrieves the new user who is the recipient of migrated resources from the old user.

These both OldUser and NewUser will be able to retrieve from UserAccessBean of concern JSP.

migrateOrderItem(OrderItemAccessBean abOrderItem, UserAccessBean abNewUser, CommandContext newUserCmdCtx)

This method migrates an order item to a new user.

1
arunlepuru On

In login page add this code when user Guest and OrderItemMove is out of box command used

<pre>
          <c:if test="${userType == 'G'}">
        <wcf:url var="orderMove" value="OrderItemMove" type="Ajax"> 
            <wcf:param name="toOrderId" value="."/>
            <wcf:param name="deleteIfEmpty" value="*"/>
            <wcf:param name="fromOrderId" value="*"/>
            <wcf:param name="continue" value="1"/>
            <wcf:param name="createIfEmpty" value="1"/>
            <wcf:param name="calculationUsageId" value="-1" />
            <wcf:param name="calculationUsageId" value="-2" />
            <wcf:param name="calculationUsageId" value="-7" />
            <wcf:param name="updatePrices" value="0"/>
        </wcf:url>  
    </c:if>
</pre>

Button javascript code User clicks on :

LogonSubmit(document.Logon,'<c:out value='${orderMove}'/>','<c:out value='${afterOrderCalculateURL}'/>');void(0);">

After validation and form the URL

function LogonSubmit{
var completeOrderMoveURL = orderMoveURL;
completeOrderMoveURL = completeOrderMoveURL + "&URL=OrderCalculate?URL=" + afterOrderCalculateURL +"&calculationUsageId=-1&calculationUsageId=-2&calculationUsageId=-7";
document.getElementById('URL').value  = completeOrderMoveURL;
}
        //Then submit the form
        form.submit();

I hope this Help for merging the items after login