Ucommerce parse niceurl or set context - umbraco

I'm trying to get the current category from the url e.g. http://localhost/catalog/discs/c-24/c-92 (generated from GetNiceUrlForCategory()). But when I call SiteContext.Current.CatalogContext.CurrentCategory, returns null.
SiteContext.Current.CatalogContext.CurrentCatalogue and SiteContext.Current.CatalogContext.CurrentCatalogueGroup do not return null.
Is there another internal call where I can parse the URL or should I write my own?
Can I set the context from the URL?

Check hostnames, it looks like they are not set for localhost

Related

How to get item table values using OData Model?

I have a OData model and data is as follows
Here, Under ZRECRUITMENT_TRACERRzSet(1), I have "toCandidates" which is Association and it has item level data.
How can I access it's values in the controller.
I tried using
oModel.getProperty('/ZRECRUITMENT_TRACERRzSet(1)/toCandidates')
But it's not helping.
You need to set the 'expand' property in your binding, so whenever the request is sent to the OData service, the "toCandidates" node will come with the data in the response, and not the URL only. Then your getProperty(...) will give you the data.
Whenever you are binding your data you need to do something like this (for example with ElementBinding):
oMyControl.bindElement({
path: "/ZRECRUITMENT_TRACERRzSet(1)",
parameters: {expand: "toCandidates"}
});

Grails: Accessing the request paramters without wiping them out

According to the document on command objects and data binding. Once you read the params object, that object can never be reused again.
From the documentation:
Binding The Request Body To Command Objects
http://grails.org/doc/2.3.x/guide/theWebLayer.html#commandObjects
Note that the body of the request is being parsed to make that work. Any attempt to read the body of the request after that will fail since the corresponding input stream will be empty. The controller action can either use a command object or it can parse the body of the request on its own (either directly, or by referring to something like request.JSON), but cannot do both.
I'm trying to view the parameters within a filter (which is hit before the controller is requested). Would logging the parameters to a log cause the controller to get a null param object? From the documentation that looks to be the case. However, how can I get access to the params without wiping them out in the filter?
Once you read the params object, that object can never be reused
again.
That is not correct. You can read request parameters over and over again. What cannot be read over and over again is the body of the request. The body and the request parameters are 2 different things.

MKNetworkKit - Host Name and apiPath parameters

I was thinking of using MKNetworkKit as base for Network operations for an iOS App. I'm a bit confused about using the initWithHostName:customerHeaders: and initWithHostName: apiPath:customerHeaders: methods.
In the App, I need to communicate to a number of hosts and they have different ways of specifying the Host Name and URL. For example:
HostNameX.com - The Domain Name for HostX,
The first host has the service prepended to the Hostname as so:
serviceA.HostNameX.com?someparam=value The Path for ServiceA (returns info)
serviceB.HostNameX.com?someparam=value The Path for ServiceB (returns info)
HostNameY.com - The Domain Name for HostY
The second host has the service or command appended to the Hostname as so:
HostNameY.com/serviceA?someparam =value The Path for ServiceA (returns info)
HostNameY.com/serviceB?someparam =value The Path for ServiceB (returns info)
For the HostNameY.com case, I was thinking of creating one MKEngine Instance and then passing in the "serviceA?someparam=value" or "serviceB?someparam=value" string as the Path parameter to the operationWithPath:params:httpMethod:ssl: method.
This would work well for what I want to do, however for HostNameX.com I'm not sure how to prepend "serviceA." or "serviceB." to the host name? The only way I can see of doing it is to create two separate MKEngine Instances one for "serviceA" and one for "serviceB". Is this the case?
Am I missing something or is there a way to be able to prepend the service to the domain name after calling initWithHostName:apiPath:customerHeaders: ?
Thanks in advance for any suggestions.
All the Best
Dave
For HostNameY.com, you are right. The service name can be part of the path.
And as you mentioned, you should use multiple instances of MKEngine to manage HostNameX.com.
Why you should use multiple instances :
Hostname is a private property of MKNetworkEngine and the only way to change the hostname is to create a new instance of MKNetworkEngine (without modifying MKNetworkEngine). Hostname property is used by MKNetworkEngine to observe Reachability changes and freeze/restore operations. If you change the hostname at runtime for a single instance of MKNetworkEngine (by making hostname property public for example), this feature won't work well on all situations. Just take a look at freezeOperations (called when you loose network) method in MKNetworkEngine.m. It checks if and operation url contains the current hostname. If you have changed the hostname and the operation was created for another host, the operation will not be archived to restore it later when the network is back.
I solved this problem by using the operationWithURLString and building my own URL String. To me anyway, this seems a much better solution than allocating a number of MKEngine Instances just to handle something that can be passed as a parameter. This way I can also append path components as well as parameters to the URL String, for example:
http://serviceA.hostname.com/fred/simmons?isvip=true&hasBooked=false
Interestingly, the parameter dictionary that is passed to operationWithURLString:params:httpMethod: works in two ways:
if the httpMethod is GET, then the dictionary is used to pass parameters in the URL, if the httpMethod is POST or PUT (or DELETE?) then the Dictionary is formatted and sent as the Request Body.
Question - is it valid to have a POST Command with parameters?
For example:
http://bookingservice.hostname.com/bookings?isvip=true&lastname=simmons
Is this a valid URL as a POST not a GET?

Using what to create cookies

Wherever I look this is the correct way to add a Cookie:
HttpCookie Session = new HttpCookie("Session");
Session.Value = someguid;
Session.Expires = somedatetime;
Response.Cookies.Add(Session);
And wherever there is no explanation as to how to get Response into the current context. So I get this error:
The name 'Response' does not exist in the current context
What do I need to do to get the above code to work?
You may want to use System.Web.HttpContext.Current.Response if you sure that this code will be executed inside web application.
But I have life-proven practice (and Law of Demeter says the same) to pass Response as a parameter to a method where I want to use it.

Recess Framework get parameter

I'm using the recess framework. Suppose I have a URL like this
www.example.com/try.php?this=5
In recess, what do i do to access the value of parameter this ??
$this->request->get['this'];
Those variables {->get[], ->post[]} populate no matter what verb is being used.

Resources