Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 289 posts 528 karma points
    Oct 14, 2011 @ 17:10
    Sean Dooley
    0

    xslt to razor assistance

    How could the following script be written in Razor?

    ./descendant-or-self::Product [not(child::Product)][1]
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 14, 2011 @ 17:27
    Dan Diplo
    0

    Tricky :)

    OK, this is just a guess and probably won't work, but I'm thinking something like this:

    CurrentModel.DescendantsOrSelf("Product").Items.
    Where(p => p.Down().NodeTypeAlias != "Product").First();

     

     

  • Sean Dooley 289 posts 528 karma points
    Oct 14, 2011 @ 18:02
    Sean Dooley
    0

    Thanks for your response Dan. Have implemented the following work around to fit my needs

    var variant = variants.Count () > 0 ? variants[0] : @item;

     

  • Sean Dooley 289 posts 528 karma points
    Oct 14, 2011 @ 18:15
    Sean Dooley
    0

    Now experiencing an error when selecting a product variant whereby the price should update like in the starter kit.

     

    <error><![CDATA[MESSAGE:
    Exception has been thrown by the target of an invocation.
    STACKTRACE:
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at TeaCommerce.Presentation.TeaCommerceBase.RequestModule.invokeMethod(restExtension myExtension, Object[] paras)

    INNEREXCEPTION:
    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at System.Xml.Xsl.CompiledQuery.Query.<xsl:template match="Product">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last, IList`1 {urn:schemas-microsoft-com:xslt-debug}namespaces) in C:\Users\Sean Dooley\documents\visual studio 2010\Projects\UnionMarket\UnionMarket\xslt\product.xslt:line 33
    at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
    at System.Xml.Xsl.CompiledQuery.Query.<xsl:template match="/">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last, IList`1 {urn:schemas-microsoft-com:xslt-debug}namespaces) in C:\Users\Sean Dooley\documents\visual studio 2010\Projects\UnionMarket\UnionMarket\xslt\product.xslt:line 21
    at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
    at System.Xml.Xsl.CompiledQuery.Query.Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.CompiledQuery.Query.Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at TeaCommerce.Data.Tools.XSLTHelper.InvokeXSLT(String xsltFile, Nullable`1 nodeId, Nullable`1 umbracoLanguageId, Dictionary`2 parameters, Boolean checkSecurity)
    at TeaCommerce.Base.InvokeXSLT(String xsltFile, Int32 nodeId, String umbracoLanguageId)]]></error>

    Below is the Razor script

    @using TeaCommerce.Razor
    @using TeaCommerce.Data
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var products = @Model.Children.Where("!umbracoNaviHide");
      var currentCurrency = TeaCommerce.GetCurrentCurrency();
      var priceProperty = @Library.Concatenate("productPrice", @currentCurrency.ISOCode);
    }
    <ul>
      @foreach(var item in products)
      {
        var variants = @item.Children;
        var variant = variants.Count () > 0 ? variants[0] : @item;
        decimal price = Decimal.Parse(@variant.GetProperty(@priceProperty).Value);
        var priceCss = String.Format(" class=\"currency{0}\"", @variant.Id);
        <li class="product" productid="@item.Id">
          <form action="/tcbase/teacommerce/SubmitForm.aspx" method="post" name="testformName" id="testformID">
            <input name="ReturnUrl" type="hidden" value="" />
            <input name="AddOrderLine" type="hidden" value="nodeId,quantity" />
            <fieldset>
              @RenderPage("RenderMedia.cshtml", @item.ProductImage, "productImage")
              <div class="description">
                <a href="@item.Url">@item.Name</a>
                @item.ProductShortDescription
                <p class="productPrice">
                  Price: <[email protected](priceCss)>@TeaCommerce.FormatPriceWithSpecificCulture(@price, @currentCurrency.CultureName)</span>
                </p>
                @if(variants.Count() > 0) {
                  <p class="productVariants">
                    <select name="nodeId">
                      @foreach(var v in variants) {
                        var selected = @variant.Id == @v.Id ? "selected" : "";
                        <option value="@v.Id" @Html.Raw(selected)>@v.Name</option>
                      }
                    </select>
                  </p>
                } else {
                  <input name="nodeId" type="hidden" value="@item.Id" />
                }
                @if( (@TeaCommerce.GetStock(@item.Id) > 0) || (@TeaCommerce.GetStock(@item.Id) == null) ) {
                  <p class="productAddToCartWrap">
                    Quantity: <input type="text" name="quantity" value="1" />
                    <input type="submit" value="Add to cart" class="productAddToCart" />
                  </p>
                }
              </div>
            <fieldset>
          </form>
        </li>
      }
    </ul>

     

     

  • Anders Burla 2560 posts 8256 karma points
    Oct 14, 2011 @ 22:47
    Anders Burla
    0

    Looks like its an int value again that isnt sent to the server or some html that is missing again - could you try and shorten your output down until it works again - and then maybe we could narrow the problem down into a single line of code - instead og 20 :)

  • Sean Dooley 289 posts 528 karma points
    Oct 17, 2011 @ 11:22
    Sean Dooley
    0

    Looking through the code, the issue occurs with the javascript invoking an xslt file. If I am looking to use Razor, are there any recommendations you can provide to resolve this issue?

  • Anders Burla 2560 posts 8256 karma points
    Oct 17, 2011 @ 11:45
    Anders Burla
    0

    Yes - you would have to do a little more work than else - you will have to remove the xslt invoke call and do the update of the ui in javascript instead. But I dont have examples as I think you are one of the first to go full Razor with Tea Commerce.

  • Kouzzmitch 13 posts 36 karma points
    Nov 02, 2011 @ 20:21
    Kouzzmitch
    0

    Good Evening

    How can i implement this query in xslt in razor script

    select="current()/descendant::Product[string(umbracoNaviHide)='0' and local-name(./parent::*)!='Product' and (teacommerce:GetStock(@id) ='' or teacommerce:GetStock(@id) &gt;0)]"

    Tried like this but no use

                dynamic nodes = item.Descendants("Product").Where("Visible").Where("Parent.NodeTypeAlias != \"Product\"");
                IEnumerable query = nodes.Where(node => TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) == null or TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) >= 0)"); //

  • Anders Burla 2560 posts 8256 karma points
    Nov 03, 2011 @ 01:03
    Anders Burla
    0

    Hi Kouzzmitch

    Thanks for your question - im not that god with Razor - but hope that Sean can help me out here - else try and post it in a razor post in the forum - I know its Tea Commerce data - but think the questions is more of technical details of Razor than about Tea Commerce. But please Sean - help me :)

  • Sean Dooley 289 posts 528 karma points
    Nov 04, 2011 @ 09:52
    Sean Dooley
    0

    Hi Kouzzmitch

    Apologies for not replying sooner as I have busy with work commitments/deadlines. Couple of questions

    What site structure have you got?

    Does the below line return anything?

    dynamic nodes = item.Descendants("Product").Where("Visible").Where("Parent.NodeTypeAlias != \"Product\"");

  • Kouzzmitch 13 posts 36 karma points
    Nov 04, 2011 @ 22:11
    Kouzzmitch
    0

    Hi Sean,

    thanks for the reply. the main issue is how to call this teacomerce stock filter methods right in query, on order to calculate items which are in stock.

    this query does return items

    dynamic nodes = item.Descendants("Product").Where("Visible").Where("Parent.NodeTypeAlias != \"Product\"");

    This don't works and I think I'm not doing it right

    dynamic nodes = item.Descendants("Product").Where("TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) == null or TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) >= 0");

  • Sean Dooley 289 posts 528 karma points
    Nov 07, 2011 @ 11:34
    Sean Dooley
    0

    Could you change TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) == null to TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) != null so the code reads as follows

    dynamic nodes = item.Descendants("Product").Where("TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) != null or TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) >= 0";

    Does that make any difference?

  • Sean Dooley 289 posts 528 karma points
    Nov 11, 2011 @ 14:27
    Sean Dooley
    0

    Hi Kouzzmitch

    Have you had any luck resolving the problem?

  • Kouzzmitch 13 posts 36 karma points
    Nov 13, 2011 @ 11:59
    Kouzzmitch
    0

    Sorry for not replying for a long and sorry from initially not describing the error completely

    Im sure it's not an Teacommerce problem at all but i hoped that you know the answer

    The matter is that when I create script

    @foreach (dynamic variant in product.Descendants("Product").Where("TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) == null or TeaCommerce.Razor.TeaCommerce.GetStock(node.Id) >= 0"))

    i get an error

    No applicable method 'GetStock' exists in type 'String'

  • Sean Dooley 289 posts 528 karma points
    Nov 15, 2011 @ 18:50
    Sean Dooley
    0

    Hi Kouzzmitch

    Try something like the following

    foreach (dynamic variant in product.ChildrenAsList.Where(x => TeaCommerce.GetStock(x.Id) != null || TeaCommerce.GetStock(x.Id) >= 0))

    Let us know how you get on

  • Sean Dooley 289 posts 528 karma points
    Nov 15, 2011 @ 18:54
    Sean Dooley
    0

    Or the following might work better

    foreach (dynamic variant in currentNode.Descendants("Product").Items.Where(x => TeaCommerce.GetStock(x.Id) != null || TeaCommerce.GetStock(x.Id) >= 0))

    Hope this helps

  • Kouzzmitch 13 posts 36 karma points
    Nov 15, 2011 @ 19:47
    Kouzzmitch
    0

    It keeps telling an error

    dynamic nodes = item.Descendants("Product").Items.Where(x => TeaCommerce.Razor.TeaCommerce.GetStock(x.Id) == null || TeaCommerce.Razor.TeaCommerce.GetStock(x.Id) >= 0));

    Error    3    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type   

  • Sean Dooley 289 posts 528 karma points
    Nov 16, 2011 @ 14:39
    Sean Dooley
    0

    I was casting currentNode as DynamicNode.

    Could you cast item as a umbraco.MacroEngines.DynamicNode? If not, uQuery (uComponents) GetChildNodes() might be what you are looking for.

  • Kouzzmitch 13 posts 36 karma points
    Nov 20, 2011 @ 14:36
    Kouzzmitch
    0

    Yes it helped but the resulting object type is Enumerator but i'll find How to count items in it

Please Sign in or register to post replies

Write your reply to:

Draft