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.

  • Dan Sunesen 45 posts 145 karma points
    Feb 12, 2013 @ 15:05
    Dan Sunesen
    0

    Get related product URL from another category

    Hey guys,

    So I have these products, which I want to relate to each other. This works great, except getting the right URL for each related product.

    There are to methods to get a product url:

     

    public static string GetNiceUrlForProduct(
        string catalogName,
        string sku
    )

     

    http://www.ucommerce.dk/docs/html/M_UCommerce_Xslt_CatalogLibrary_GetNiceUrlForProduct.htm

     

    public static string GetNiceUrlForProduct(
        string catalogName,
        string categoryName,
        string sku
    )

     

    http://www.ucommerce.dk/docs/html/M_UCommerce_Xslt_Library_GetNiceUrlForProduct_1.htm

     

    Say I have product in category "walking", which I relate to a product in category "seating". How do I get the link for the related product in seating, when I'm on the walking-product page?

    The first method doesn't give me the entire url, it misses the category and thereby results in an "page not found" url.

    The second method requires the categoryName, but since i'm standing on a walking product and try to do: umb:RequestQueryString('category') - I get the current category (walking), and not the category of the related product.

     

    The XML for a related product is:

     <relatedProducts>
        <productRelationType index="0" description="Relations between products" name="Default" productRelationTypeId="1">
          <product index="0" id="163" sku="23106" displayName="ProductName" shortDescription="ProductDescription" longDescription="<p>Description</p>" thumbnailImage="" primaryImage="1187" allowOrdering="True" isVariant="False" displayOnSite="True" rating="" hasVariants="False" definition="PIM Product" price="" currency="" tax="" priceExclTax="" HideAustralia="False" HideBelgium="False" HideCanada="True" HideCzechRepublic="False" HideGermany="False" HideGlobalEnglish="False" HideEspania="False" HideHolland="False" HideEnglishUK="False" HideEnglishUS="True" LanguageKey="" />
        </productRelationType>
      </relatedProducts>

     

    I guess that if the related product had a property like this: category="theCategoryName", I would be able to retrieve the correct URL.

     

    Any suggestions?

     

    Br,
    Dan

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Feb 12, 2013 @ 15:08
    Nickolaj Lundgreen
    0

    In razor i would take the relatedProducts categories, and pick one of them (FirstOrDefault or alike).

    Im not sure how you would do that in XSLT

    (i assume you want XSLT when you mention XML)

  • Dan Sunesen 45 posts 145 karma points
    Feb 12, 2013 @ 15:11
    Dan Sunesen
    0

    Thats correct, Nikolaj - I need a way to do it in XSLT :)

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 14, 2013 @ 11:40
    David Brendel
    0

    I don't know exactly how to do it in xslt since i'm not using xslt.

    But the way in xslt should be the same as in razor:

    • Get the categories from the related product
    • Pick the first found
    • use the above method to get the url

    I think the xslt extension or the xslt library will have a method which you can use for that.

    With my little xslt knowledge i would go like:

    • Loop through the related products
    • Get the product with CatalogLibrary.GetProduct()
    • Then get the first category from product.GetCategories()

    Hopefully that get's you in the right direction

  • Dan Sunesen 45 posts 145 karma points
    Feb 14, 2013 @ 13:59
    Dan Sunesen
    0

    Hey David, I'll try and look into your suggestions! :) Thanks so far!

Please Sign in or register to post replies

Write your reply to:

Draft