Spartacus3.2- How to change sequence of Default page load API Call's - spartacus-storefront

User call is happening at end of page load. Is there any modules placed wrong? So that API call always last? Can I know How to call User API "https://spartacus-demo.eastus.cloudapp.azure.com:8443/occ/v2/powertools-spa/orgUsers/current?lang=en&curr=USD" After Pages call
?
Is there a way to change default API's order?
Thanks a lot in advance!

It seems like you are accessing the cart page. Just try to see the sequence in your cart-details.component.ts. You might be having two observables cart$ and user$. Just try to see whats the execution order is on route change using the debugger. You will get to know what's causing the issue.
Alternatively, if you want to place a cart call after the user call, it's possible. You can put your cart call inside your user call. Use subscription to do that. But I don't see the point here to do that, because your API can get a currently authenticated user with "current" in the user id param.

Related

Need to inject data to webview's session storage before it starts loading

Problem Defination:
I need to inject the authorization header to session storage of WebView, so that the server authenticates the user and redirects to the dashboard. If there is any delay in injection the WebView loads and redirects user to server's login page as it couldn't find the authorization header in the session storage.
What I tried:
onLoadStrat of WebView, I've injected the data using this.webview.injectJavaScript()
By doing so I'm able to inject the data to session storage but on first load there's a race condition. Injection takes a bit time and the Login screen has shown in place of the dashboard.
Expected Result:
We want to achieve the injection without any delay. Suggest me if there's any other way to get this working the way we want it to.
Waiting to hear from you guys. Your valuable suggestions are highly appreciated.
Thank you.
What you are facing is a direct result of asynchronous nature of React in general. You cannot stop the login screen rendering from happening (in other words, the render() function cannot be stopped). But what you can do is, you can inject the data into sessionStorage and then once it is set, change some variable in the state of the component. This will force the component to re-render but this time you will have the data injected. So here are the steps:
1.) Let it render first (you cannot stop it and stopping it anyways is anti-pattern).
2.) Inject the data as you need it to.
3.) Change the state of the component as soon as step 2 is done.
All of this should happen very fast and should not be visible to the end user, imo.

Track last view with C# ASP.NET MVC

I don't have any code to show, because I'm not sure how to approach this. I am sending a user from one view to another where we will be doing CRUD OPERATIONS, I need to have a way of knowing what the last view I came to before the CRUD OPERATION so that I can send my user back to that view. I would also like to use this for redirection once someone has logged in. I want to have a way of setting the view I want them to get sent back to so that they can log in from any page on the site and it will remember that page instead of just dropping you on the home page.
I would accept a good tutorial as well, I'm pretty desperate to figure this out. SHoudl I just use ViewBag?
If you making <a></a> Through Html Helper then you globally set the querystring in function that can be later used for know the last view user visit.
As Balachandra mention you can use ReturnUrl inside the Request object.
Some other idea which can help you are
Request.Server["HTTP_REFERER"]
Request.UrlReferrer
A another simple algorithm to solve this issue is making JavaScript cookie to know what is current url. and last url. it's only take 2 url to remember in cookie.
When you want to know last referrer then you can easily look in user cookie to know the referrer.
If you want to know the url refeffer in inside Action then make a ActionFilter and just call this code
HttpContext.Current.Request.UrlReferrer.ToString()
In ASP.NET MVC we have TempData which used to pass Data from Views to Views. From this post http://www.rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications You can get better explanation.
This are enough Tricks to pass the data from Views to Views. For Example TempData will help you to store current url and you can get same information on next view. Remember that TempData is based on Session so it doesn't store the information for long time. For me TempData look perfect solution that you need to use for your own solution.
If you enable asp.net mvc authentication and try to browse any page in application, it will redirect user to login page with 'ReturnUrl' querystring parameter. This parameter holds the name of previous page from where user redirected from.
You can use similar approach even after login as well.

ASP.NET MVC - check Facebook login status

This is more of a design question.
I figured out how to use the facebook login via the Facebook SDK c#.
QUESTION: What is the best way to check whether the user is logged into FB or not each time the user goes to a different page?
Back on ASP.NET webforms, I could simply put in code to check FB login status in the code behind of a master page. This was good ... once and done. But I don't understand how to implement something similar in Asp.Net MVC 4.0.
Given that the _Layout.cshtml file (which acts like a master page) is only a view (hence, no code behind), what is the best way to code a way to check if the user is logged into FB each time a user goes to a different web page? Because I would think, adding this bit of code to each controller can't be the optimal design solution.
The only solution that I can think of involves using Javascript on the client side to do a WebApi call ... I guess the script will be bundled with all the other scripts so that it runs on each page. But I was hoping to find a solution on the server side ...
I'm pretty new to MVC, learning things as I go along ... tips appreciated ... thanks!
I can think of a couple of points that might help you devise a solution.
You can put code in your _Layout, but I agree that you want to be careful about doing so. You could create a helper or partial view and have your _Layout call it so that it's executed for every action. Your helper/partial would need to execute the required logic and then return something. The problem that I have with this is it's a lot of overhead every request.
You could do an AJAX call after the page is loaded (as you suggested). This means that the page still loads quickly. The problem I have with this is that you're now dependant on Javascript. It's also potentially a little hacky(?)
What about storing the user's status (logged on/off) in a session/cookie and also providing a 5 minute expiry. You can use the Helper/Partial method from before or have some logic fire in OnActionExecuting (or similar). Your logic should check to see if the status has expired and then connect to the Facebook API to update the status. This has the advantage of low overhead (i.e. not checking again until 5 minutes has passed).
I don't know of your exact situation so I can't say what method, if any, is best.

How do I know the offset for each limit?

When I use LIMIT to make pages of results, how do we usually know the offset i.e. which page should be retrieved for each request?
Via cookies?
Via a query string parameter, traditionally. URLs typically include a ?page=3 to request page 3, like you'll see all over Stack Overflow: https://stackoverflow.com/questions?page=2&sort=newest
This is something you absolutely should not do through cookies. The URL should include everything necessary to navigate to the given page. Consider a user bookmarking page three of your results, or trying to link somebody else to the page they're looking at: Using cookies to store pagination data breaks these situations completely.
Usually via request parameters in action frameworks (RoR, ZF, Cake, Django) and via state of the session in component frameworks (Prado, JSF, ASP.NET). Session is usually associated with request by a cookie.
Using session to store current page is quite common in business-oriented applications, where state of the gui might be very complicated and the practically of being able to bookmark a page - limited.

Is there a way to hook into the checkout event in Magento?

I'm creating a custom module that needs to hook in to the checkout success event in Magento.
What I need to do is this:
1). Once a custom has successfully checked out I need to present a special offer on the success page with a yes/no radio button and submit form. If they select yes I need to add their details to a custom grid in Magento backend that I have already created.
2). I then need to make an API call to a third party CRM using the POST method to authenticate and add the customers details to their billing system.
3). Upon completion there needs to be a way to update the Grid in Magento to change state from "pending..." to "accepted"
I have started the module but I just can't seem to find any clear documentation about making API Calls or POST requests from Magento that I'm beginning to wonder if this is actually possible?
I would be grateful if anyone knows of an extenion or documentation on how to do the above or if they know of a simpler solution...
If neccessary I can submit my module on Github as a reference if someone is able to assist me
Many thanks!
add a custom block to the checkout_onepage_success layout handle via XML. This block will contain your form.
in the controller that processes your form, you can use Zend_Http_Client to make the POST request to the third party API. Alternatively Zend_Rest_Client or Zend_Soap_Client or Zend_XmlRpc_Client if any of these protocols are used. All of those Zend packages are readily available in Magento.
this is just basic loading and updating models, you should already know how to do this