Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Kenny Burns 173 posts 305 karma points
    Feb 28, 2012 @ 13:59
    Kenny Burns
    0

    Razor Functionality

    Hi Guys,

    We are currently trying to get our head around the exapnsive amount of functions available within uCommerce and looking at the XSLT demo store example and trying to look at the functions in order to convert them to razor.

    Would we still use UCommerce.XSLT to call some functions like 'Library.EditBillingInformation'?

    Example:

    using UCommerce.Xslt;

    protected void btnContinue_Click(object sender, EventArgs e)

        {

         Library.EditBillingInformation(txtFirstname.Text, txtSurname.Text, txtEmail.Text, txtTelephone.Text, txtMobile.Text, txtCompany.Text, txtAddress1.Text, txtAddress2.Text, txtPostcode.Text, txtCity.Text, txtCounty.Text, "", Convert.ToInt32(ddlCountry.SelectedValue));

        }

    I have also seen in some examples using UCommerce.EntitiesV2 - is this more used for calling product information etc?

    And finally UCommerce.Runtime seems to be used for things like basket totals?

    Is this correct and are we on the right path or have we missed something? We would prefer to create our macros from Razor files as we are more comfortable with Razor than XSLT.

    Any help greatly appreciated!

    Thanks

    Kenny

    
    

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 01, 2012 @ 14:26
    Dan Diplo
    0

    I was just coming to this forum to ask a similar question:

    For instance, I've still found I have to use UCommerce.Xslt.Library.GetNiceUrlForCategory to get the URLs for a list of categories. This doesn't really "feel" right. Is there a better way? Ideally it would be nice if the Category class had a URL method.

    If we still have to use  UCommerce.Xslt.Library then perhaps it could be aliased in another more meaningful namespace?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 01, 2012 @ 15:00
    Dan Diplo
    0

    Also, is there a better way of initialising entities from the values passed in the query string? At the moment I'm doing something like this:

        int catalogId;
        ProductCatalog catalog = null;
    
        if (int.TryParse(Request.QueryString["catalog"], out catalogId))
        {
            catalog = ProductCatalog.Get(catalogId);
        }
    

    Is there a better way than this? I was going to make my own library, but wanted to check I wasn't reinventing the wheel.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Mar 05, 2012 @ 10:20
    Søren Spelling Lund
    0

    @Kenny: Using the XSLT functions will in many cases save you some time as they deal with the underlying objects for you. So all in all much easier to work with. You can of course drop down a level and work with the objects themselves. This is pretty common to do if you need to override specific behaviors in the API.

    @Dan:

    Regarding the URL you can use the XSLT library, but also you can leverage our DI container directly:

    var urlService = ObjectFactory.Instance.Resolve<IUrlService>();
    urlService.GetUrl(catalog); 

    The way you're loading objects is just right. We tend to use extension methods and hook them up on the CatalogContext, so you can go

    ProductCatalog catalog = SiteContext.Current.CatalogContext.GetCurrentCatalog();

    The extension method essentially encapsulates the code you posted, but saved some duplication and makes it a little simpler to work with. Here's what the extension method looks like:

    public static ProductCatalog(this ICatalogContext target)
    {
    string catalogIdStirng = Request.QueryString["catalog"];
    int catalogId; ProductCatalog catalog = null; if (int.TryParse(catalogIdString, out catalogId)) { catalog = ProductCatalog.Get(catalogId); }

    throw new ConfigurationErrorsException(string.Format("Catalog with id {0} not found", catalogIdString));
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 05, 2012 @ 20:09
    Dan Diplo
    0

    Brilliant, thanks Soren! I find it always best to get a bit of expert advice before embarking too far down the road.

  • Kenny Burns 173 posts 305 karma points
    Mar 06, 2012 @ 10:43
    Kenny Burns
    0

    Thanks Soren! 

Please Sign in or register to post replies

Write your reply to:

Draft