Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rachel Skuse 88 posts 118 karma points
    Mar 22, 2011 @ 17:20
    Rachel Skuse
    0

    Using a node from a another page

    Hi,

    I have created a Store Locator in a usercontrol that uses our company database to find the nearest store to a postcode that is entered. The store results get returned as a list but I need the user to be able to click through for more information. All stores have their own page in Umbraco and I'm wondering how I assign the url of that page to a 'more info' button in the list of results? I'd also like to return a thumbnail in the list view which is a node on the shop pages. Is it possible to link something like 'postcode' which exists in the database and the umbraco pages?

    Thanks,

    Rachel

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 17:52
    Tom Fulton
    0

    Hi Rachel,

    Probably the best way to do this is to store the Node ID of the Store in the database with your other details (if you're not already).

    Then you can get the URL from your usercontrol using:

    umbraco.library.NiceUrl(id)

    And you can retrieve properties (for your thumbnail etc) using NodeFactory:

    using umbraco.NodeFactory;

    Node n = new Node(id);
    n.getProperty("yourFieldAlias").Value;

    Not exactly sure what you mean by linking the postcode - do you want it to be updateable from both places?

    Hope this helps,
    Tom

  • Rachel Skuse 88 posts 118 karma points
    Mar 22, 2011 @ 18:03
    Rachel Skuse
    0

    Hi Tom,

    Thanks for your quick response. I was hoping to avoid having to store the Node ID in the database as this is a generic database that is used across many different brands (I'm only developing for one of these brands!) and I don't think our SQL guys will thank me very much!!

    Sorry, I didn't explain myself very well re. the postcode. I return the postcode of the store in the list of results but this postcode is also already present in the store page so I was wondering if I could some how do a search of all the shop pages to match the postcodes??

    Thanks,

    Rachel

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 18:21
    Tom Fulton
    1

    Hmm, ok.  Well somehow I think you'll need to associate a Store from your database to a Node, if you want to interact with the Umbraco node properties (URL, Image, etc) from the database record.  Otherwise how would you retrieve the node?  Is there some other unique identifier that's on both the node and the DB record?

    You could do this the reverse way, add a field on your Store document type in Umbraco, that allows you to select the associated "store record" from the database.  Though if you have 100's of stores that might not be fun :)

    Then from your usercontrol you could find the Umbraco node with the matching record ID from the database.  uQuery would probably be best for this.  I haven't used it yet but would imagine you can do something like uQuery.GetNodesByXPath("//YourStoreDocTypeAlias [storeRecordId=" + id_from_database + "]");

    For the field to store the "store record ID" you could create a custom datatype that reads from the Store database, so it's easy to select.

     

    Regarding the postcodes, uQuery is probably best for that as well.  Something like:

    foreach (Node n in  uQuery.GetNodesByXPath("//YourStoreDocTypeAlias [postCode=" + postcode + "]"); { ... }

    I think you can also use .Where in uQuery, something like

    uQuery.GetNodesbyType("YourStoreDocTypeAlias").Where(n => n.GetPropertyAsString("postCode") == postcode)

    Is your search logic only searching by the postcode?  If so maybe its possible to eliminate the database and just search the nodes?  Would probably be a lot easier :)

    Hope this makes sense
    Tom

  • Rachel Skuse 88 posts 118 karma points
    Mar 23, 2011 @ 09:55
    Rachel Skuse
    0

    Thanks for the suggestions Tom - I'll give them a try!

    Rachel

Please Sign in or register to post replies

Write your reply to:

Draft