Can I use a Query String to drive personalized content in Sitecore 7.5? - sitecore

I'm trying to display personalized content on a page IF I have clicked on a specific link on a specific page. My thought was to have a parameter on the link such as:
Go to product page
Then, on "Product Page", hopefully using the rules engine, check if the parameter home exists in the query string. If so, then display a piece of content.
I can't seem to figure out the best way to do this with Sitecore 7.5. Maybe this is the wrong approach.

Out of the box in Sitecore 7.5 there is no rule for using the querystring.
but you can easily create a rule and use with the personalize feature from Sitecore.
See http://blog.martinmiles.net/post/rules-engine-and-sitecore-personalization-based-on-url-query-string-parameters
for a complete description and Example include a link to github with the code
https://github.com/MartinMiles/Personalization

so you would have to have something like this:
public ActionResult Index(string name)
{
Student student = new Student();
student.Name = "John";
if (!String.IsNullOrEmpty(Request.QueryString["name"]))
{
student.Name = Request.QueryString["name"];
}
return View(student);
}
For this example, my controller is named Test. So if I want to call this method I would do ~/test/index, if I do that the student object will contain the name John, however if I do ~/test/index?name=Denis , I will send an object with the name Denis
Here the name will only change when we pass the query string "name" with a value.

Related

Set default values when creating contact from lead

I added a few custom string fields using NameValuePair in the Lead form (CR301000). Using the an Action, I create a contact from the lead. I added the same custom fields to my Contact form (CR302000). How can I get the custom values from my lead to my new contact? I tried using the following:
[PXFormula(typeof(Selector<CRLead.contactID, ContactExtNV.usrCROnline>))]
I'm going to have the same issue when I create an account from the lead. Is there a better way to do this instead of using PXFormula?
The Selector parameter for the PXFormula attribute looks like this:
Selector –> Selector<KeyField, ForeignOperand>
KeyField-> The key field to which the PXSelector attribute should be attached.
ForeignOperand-> The expression that is calculated for the data record currently referenced by PXSelector.
That is, in your case it turns out like this:
[PXFormula(typeof(Selector<Contact.contactID, CRLeadExt.usrCROnline>))]
public string UsrCROnline { get; set; }
Adding namespace in the source code using Customization Project Editor

How to get Zomato restaurant ID using restaurant link?

I want to get details of a restaurant in Zomato. I have it's link as the input (https://www.zomato.com/mumbai/fantasy-the-cake-shop-kalyan?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1). By browsing the documentation of Zomato APIs, I didn't found a way to get it.
I tried searching for the restaurant using search API but it returns many results.
Any help will be appreciated
It's a two-step process:
Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan
This would give all the basic information about a restaurant.
View the page's source and search for window.RES_ID
I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.
This worked for me:
Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
var url_in_json = body.restaurants[i].restaurant.url;
if (url_wanted.valueOf() == url_in_json.valueOf()) {
var restaurant_id = body.restaurants[i].restaurant.id;
}
console.log('Voala! We have res_id:' + restaurant_id);
}
There you have it. It could be easier though.
Hope it helps!
once you have the url of the rseraunt's page you can simply look for a javascript object attribute named "window.RES_ID" and further use it in the api call.

How to get user info into a web forms for marketers form automatically

I try to get the login information present in the header of my Sitecore intranet automatically within a web form (from marketer) so that the logged person has not the reenter that user information already present on page.
Someone any feedback or experience therewith?
You can use rules for this. Look at each field property and one of these at the bottom are rules you can assign to the field.
One of the rules is populating the default value from the user profile field.
Hopefully this is what you are after.
I think you should create a custom field type.
Here is the documentation on page 55: web forms for marketers.
Here is the sample code snippet to get user e-mail:
public class UserDataEmailField : BaseControl
{
/// <summary>
/// Gets the result.
/// </summary>
public override ControlResult Result
{
get
{
var item = Sitecore.Context.Database.GetItem(this.FieldID);
return new ControlResult(item.Name, Sitecore.Context.User.Profile.Email, string.Empty);
}
}
}
You should overwrite also the Render method.
I hope I helped.

FactoryGirl first created object used even when specify the second one

I can't really understand this. I have a course factory that I use to create two objects. When I visit the page for the Accounting course (as seen below) it displays the Marketing course page. However, if I use factory girl to create the accounting course first then it visits the correct page and the test passes.
describe "Course pages" do
subject { page }
let!(:published_course) { FactoryGirl.create(:course, title: 'Marketing') }
let!(:unpublished_course) { FactoryGirl.create(:course, title: 'Accounting') }
describe "displaying the right page" do
it "should display the accounting course page" do
visit course_path(unpublished_course)
expect(page).to have_content('Accounting')
end
end
end
It obviously visits the page of the object that is created first, but I don't know why or how to fix this.
Thanks,
Matt
course_path will generate the correct URL (i.e. containing the correct id param), but it's up to your controller to find the course for that id and pass it to your view. Instead, your controller/view must be conspiring to display the first course created.

How sitecore 7 maps template with class

I have downloaded Sitecore 7 Autohaus demo for learning purpose.
I notice that in Autohaus code, there is a model - Car.
I would like to know how does sitecore know how to map between Car model (code) and CarModel template (sitecore template).
There are a few more steps between the car template and the car object model.
One of the main features of Sitecore 7 is the embedded search capability. When items, created from the car template, are saved, that information is stored in a search index (Lucene or Solr)
The Car model is not mapped directly from the template or the database item but from the search document created.
When you use the LINQ layer e.g.
var index = ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = index.CreateSearchContext())
{
var query= context.GetQueryable<Car>()
.Where(item => item.Seats == 2);
}
Sitecore will execute a search and then take the 'Car' object and populate/hydrate it with the information from the search results by use of Sitecore's DocumentMapper.
This will populate public properties and also indexers of the Car object. The DocumentMapper takes care of casting to and from object types for you (such as DateTime / int etc).
The DocumentMapper will try and map properties with matching field names but you can place attributes on the object properties to help Sitecore map specifically to your objects.
This example tells Sitecore to map the field 'modelkey' to the property ModelId.
[IndexField("modelkey")]
public string ModelId { get; set; }
You can see the LINQ queries used in Autohaus on most of the pages and should be a great resource for learning how Sitecore 7 works.
More info about various parts of Sitecore 7 can be found here: http://www.sitecore.net/Community/Technical-Blogs/Sitecore-7-Development-Team.aspx