In IBM WCS, what happens when a user logs in after adding an item to cart as a guest. How is the orderId handled in this scenario? - websphere-6.1

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.

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.

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.

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

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

Related

How can i trigger zendesk web widget after page reload?

I create custom ticket form in zendesk and passing some parameters (like customer name, customer email, and customers company name) from my database. then i found zE(identify) functions and saw this functions include just name and email object. but i need customers company names too. and it is just came after completely page reload.
So how can i refresh (or something) after database value completely reload?
sorry for my bad english
To execute zE function after page load you should be able to add it to a callback function from however you are loading the DB values.

Output cache (Local vs Custom)

I was searching for a local cache solution to store output cache in user browser so that each user has his own cache, and i arrived to use he following profile:
<add name="Cache30MinClient" duration="1800" varyByParam="none" location="Client" noStore="true" />
However i found the following post which state that user cache is done by varyByCustom attibute .
My question is: Is my solution enough for caching data in user browser or should i follow that post?
Thanks.
It depends :) GetVaryByCustomString essentially lets you to select piece from http request that can be used as cache key. In your solution (I'm kind of missing the controller piece) your cache key is empty - so every single user will get the same result - this may be fine if the users are anonymous or if the fact that user is authenticated or not doesn't play a role in output html.

ASP.NET MVC, BDD, Specflow and WatiN: putting the application in a specific state

I'm new to BDD, Specflow and WatiN. I would like to use these tools to automate acceptance tests for my ASP.NET MVC application.
I've already figured out how to basically use these tools, and I successfully built my first acceptance test: Log on to the website.
Here is the Gherkin for this test:
Feature: Log on to the web
As a normal user
I want to log on to the web site
Scenario: Log on
Given I am not logged in
And I have entered my name in the username textbox
And I have entered my password in the password textbox
When I click on the login button
Then I should be logged and redirected to home
Now, I would like to write a bunch of other tests, and they all require the user to be authenticated. For example:
Feature: List the products
As an authenticated user
I want to list all the products
Scenario: Get Products
Given I am authenticated
And I am on the products page
When I click the GetProducts button
Then I should get a list of products
What bugs me is that to make this test independent of the others, I'd have to write code to log on the website again. Is this the way to go? I doubt.
I'm wondering if there are best practices to follow for testing scenarios like that. Should I keep the browser open and have the tests run in a specific order, on the same browser? Or should I put the MVC application in a specific state?
For this, we have a specific Given step, that looks something like this in Gherkin:
Given I am signed in as user#domain.tld
Like you mentioned, this step basically reuses other steps to sign in the user. We also have an "overload" that takes a password, in case the test user has a non-default test password:
Given I am signed in as user#domain.tld using password "<Password>"
[Binding]
public class SignInSteps
{
[Given(#"I am signed in as (.*)")]
public void SignIn(string email)
{
SignInWithSpecialPassword(email, "asdfasdf");
}
[Given(#"I am signed in as (.*) using password ""(.*)""")]
public void SignInWithSpecialPassword(string email, string password)
{
var nav = new NavigationSteps();
var button = new ButtonSteps();
var text = new TextFieldSteps();
var link = new LinkSteps();
nav.GoToPage(SignOutPage.TitleText);
nav.GoToPage(SignInPage.TitleText);
nav.SeePage(SignInPage.TitleText);
text.TypeIntoTextField(email, SignInPage.EmailAddressLabel);
text.TypeIntoTextField(password, SignInPage.PasswordLabel);
button.ClickLabeledSubmitButton(SignInPage.SubmitButtonLabel);
nav.SeePage(MyHomePage.TitleText);
link.SeeLinkWithText("Sign Out");
}
}
I think this is the best approach, since you should not be able to guarantee that all of the tests run in a specific order.
You may also be able to do this with a SpecFlow tag though, and have that tag execute BeforeScenario. That might look something like this:
Feature: List the products
As an authenticated user
I want to list all the products
#GivenIAmAuthenticated
Scenario: Get Products
Given I am on the products page
When I click the GetProducts button
Then I should get a list of products
[BeforeScenario("GivenIAmAuthenticated")]
public void AuthenticateUser()
{
// code to sign on the user using Watin, or by reusing step methods
}
...should I put the MVC application in a specific state?
When signing in users, it's not the MVC application that needs to be put into a specific state, but rather the browser that needs to be put into a specific state -- namely, writing the authentication cookie. I'm not sure if you can do this or not, given that the auth cookie is encrypted. I always found it easier to just let SF walk though the authentication steps at the beginning of each scenario.
You might want to consider further refining your solution. Have a read of Dan North's Who's Domain is it anyway and then ask yourself if these two scenarios actually belong together. I've found there is value in the approach that danludwig has suggested, but there's more value in separating your scenarios according to their domain. Think of it as refactoring your scenarios.
You can still build one scenario from the activities of another, but ask yourself, do you really need to go through the same steps, or would providing a mocked "Already logged in" object to your session work better.

Sharepoint 2007 approval email

in our Company we have a Sharepoint 2007 Server which we are using to keep track of our cars.
What I try to achieve is to have a aspx page where you can select a car of the cars list and then click "request". If you did that the page must switch to another text saying something like "car request in progress" (and of course hide this car in the cars list if the next person enters this page) and send an email to someone which contains two buttons: "accept" "decline". If he clicks "decline" the cars status has to be set to available again so someone else can do a request for this car again. if he clicks "accept" another person gets an email telling him that person1 requested this car and this has been approved by person2. this emails are easy to create using workflows which are waiting for the status to change but how can i create a link which changes a cars statusfield in the cars list and what code do i need in the aspx request page?
Thanks in advance!
MemphiZ
Make a link that, when clicked, will run the appropriate action on the users behalf. If you are using workflows, this is as "simple" as changing the items property and letting the item-change event be handled. Make sure to avoid cyclic changes.
This can be done trivially by encoding the items GUID (and perhaps list and action and whatever else you want) in the URL; the GUID can be used with the SharePoint Object Model for the lookup.
Perhaps the above can be done using SPD without a separate/"code" ASPX, but I don't touch that pile of "fun".
Edit for comment:
In my scenario we just encoded the link as http://foo.com/whatever.aspx?id={THEGUID}. The aspx handler just read the query parameters. Item editing ability used standard SharePoint list permissions. Double-submissions were rejected because after the link is handled the item modified to be in a new state which does not accept said link-action (thus clicking the link again simply resulted in no-operations). Working out a total state-diagram before starting work can save lots of time.

Saving data in rails session to use in form on next request

Let's say I have a table called positions (as in job positions). On the position show page I display all the detail about the job - awesome. At the bottom I need the prospective applicant to input their professional license # before continuing onto the next page which is the actual applicant creation form. I also need to take that license # and have it populate that field on the applicant form (again on the proceeding page).
I realize there are a couple ways to do this. Possibly the more popular option would be to store that value in the session. I am curious how to do this in the simplest manner?
My idea:
Create a table specifically for license #'s.
Add a small form on the position show page to create license # (with validation)
Store newly created license in session - not sure what to put in which controller?
On applicant creation form populate from session the license #.
This would assume applicants only have one license.
Thoughts?
Appreciate the help!
Don't store this in the session! Pass that as an hidden field.
Let's say the user starts the form, then open the form again in a new window or something... then the session variable would be shared between the two forms. Other problems would occur if the cookie gets removed (session expire, user clear cache...)
This is not good. The best way is using a POST variable. GET works as well but messes up the URL
Seems like a good idea. As for #3, for whatever controller is called in the transition from 2 -> 4, that would be the controller where you store the session, as such:
session[:license_number] = your_license_number_information
From there, it can be called the same way (session[:license_number]) to get it.
The hidden field is safer for data persistence. However is not not then coded in the HTML output? That can be a great data security issue.
This is a trade-off to be considered.

Resources