Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 208 posts 617 karma points c-trib
    Aug 14, 2017 @ 15:37
    Lewis Smith
    0

    Adding and retrieving custom properties.

    Hi All,

    I'm trying to add two custom values at the product page (startDate and endDate)

    Then at the basket stage retrieve these values to show them, then eventually I will need to store these values in Umbraco.

    Here is the code I have so far.

    ~Lewis

    Product page code:

    <form method="post" action="/base/TC/FormPost.aspx" class="ajaxForm" data-product-id="@productPage.Id">
        <input name="AddOrUpdateOrderLine" value="productIdentifier,storeId,quantity,startDate,endDate" type="hidden" />
        <input name="storeId" value="@storeId" type="hidden" />
        <input name="productIdentifier" value="@productPage.Id" type="hidden" />
        <label>Quantity</label>
        <input class="form-control" name="quantity" value="1" type="text" />
        <input type="text" id="startDate" name="startDate" placeholder="Pick Start Date">
        <input type="text" id="endDate" name="endDate" placeholder="Pick End Date">
        <input class="btn btn-primary btn-block disabled" value="Add to basket" type="submit" />
    </form>
    

    Products / Basket page:

    @using TeaCommerce.Api.Models
    @using TeaCommerce.Umbraco.Web
    @inherits UmbracoTemplatePage
    @{
      Layout = "CartStepMaster.cshtml";
      IPublishedContent currentPage = Model.Content;
      IPublishedContent nextStep = currentPage.Children.FirstOrDefault();
      long storeId = long.Parse(currentPage.GetPropertyValue<string>("store",true));
      Order order = TC.GetCurrentOrder(storeId,false);
    }
    @if (order != null) {
        <h1>Your cart</h1>
        <table>
            <tr>
                <th>Product</th>
                <th>Unit Price</th>
                <th>Quantity</th>
                <th>Date</th>
                <th>Update</th>
            </tr>
            @foreach ( OrderLine orderLine in order.OrderLines ) {
                IPublishedContent productContent = Umbraco.TypedContent(orderLine.ProductIdentifier);
                <tr>
                    <td>@orderLine.Name</td>
                    <td>@orderLine.UnitPrice.Value</td>
                    <td>@orderLine.Quantity.ToString( "0.####" )</td>
                    <td>@order.Properties["startDate"] - @order.Properties["endDate"]</td>
                    <td>
                        <form action="/base/TC/FormPost.aspx" method="post">
                            <input name="storeId" type="hidden" value="@storeId"/>
                            <input name="AddOrUpdateOrderLine" type="hidden" value="orderLineId : orderLineId, quantity : quantity" />
                            <input name="orderLineId" type="hidden" value="@orderLine.Id"/>
                            <input name="quantity" type="hidden" value="-1" />
                            <button type="submit" class="btn btn-default">-</button>
                        </form>
                        <form action="/base/TC/FormPost.aspx" method="post">
                            <input name="storeId" type="hidden" value="@storeId"/>
                            <input name="AddOrUpdateOrderLine" type="hidden" value="orderLineId : orderLineId, quantity : quantity" />
                            <input name="orderLineId" type="hidden" value="@orderLine.Id"/>
                            <input name="quantity" type="hidden" value="1" />
                            <button type="submit" class="btn btn-default">+</button>
                        </form>
                        <form action="/base/TC/FormPost.aspx" method="post">
                            <input name="RemoveOrderLine" type="hidden" value="orderLineId : orderLineId" />
                            <input name="storeId" type="hidden" value="@storeId"/>
                            <input name="orderLineId" type="hidden" value="@orderLine.Id"/>
                            <button type="submit" class="btn btn-default">Remove</button>
                        </form>
                    </td>
                </tr>
            }
        </table>
        <p><strong>Total: </strong>@order.TotalPrice</p>
        <nav>
          <a href="@nextStep.Url" class="btn btn-success">Continue</a>
          <a disabled="disabled" class="btn btn-default">Back</a>
        </nav>
    }
    

    Currently no dates are output on the basket page.

    Any help?

  • Lewis Smith 208 posts 617 karma points c-trib
    Aug 17, 2017 @ 15:09
    Lewis Smith
    0

    Anyone?

  • Anders Burla 2560 posts 8256 karma points
    Sep 04, 2017 @ 09:23
    Anders Burla
    0

    Hi Lewis

    Your properties are saved on an order line and not the order. That is why you get no info when you try to output properties from the order and not the order line.

    Kind regards

    Anders

  • Lewis Smith 208 posts 617 karma points c-trib
    Sep 04, 2017 @ 11:10
    Lewis Smith
    0

    Hi Anders,

    This is still isn't returning anything?

    Any suggestions?

    Thanks Lewis

  • Anders Burla 2560 posts 8256 karma points
    Sep 04, 2017 @ 11:15
    Anders Burla
    100

    Because the properties are saved on the order line and not the order. So you need to change your code to get it to work :)

  • Lewis Smith 208 posts 617 karma points c-trib
    Sep 04, 2017 @ 11:16
    Lewis Smith
    0

    Thanks,

    Just saw that! All working now!

    Working code is:

    <form method="post" action="/base/TC/FormPost.aspx">
            <input name="AddOrUpdateOrderLine" value="productIdentifier, quantity, properties" type="hidden" />
            <input name="storeId" value="@storeId" type="hidden" />
            <input name="productIdentifier" value="@productPage.Id" type="hidden" />
            <input name="quantity" value="1" type="hidden" />
            <input name="fromDate" value="1/1/11" type="text" id="startDate"/>
            <input name="toDate" value="1/1/11" type="text" id="endDate"/>
            <input name="properties" value="fromDate, toDate" type="hidden" />
            <input value="Add order line" type="submit" />
        </form>
    

    Thanks, Lewis

Please Sign in or register to post replies

Write your reply to:

Draft