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.

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Mar 11, 2014 @ 13:29
    Lars-Erik Aabech
    0

    Review request for custom order tab to edit address

    Hi guys,

    I gave adding a tab to orders a go by creating a custom user control and adding it to uCommerce_AdminTab. The purpose of the control is to edit a custom address on the order. I thought it was a bit much, but I guess it’s being rethought for vNext. :)

    Anyway, if you’d like to glance over it and give me some input:

    <%@ Control Language="C#" ClassName="OwnerAddress" %>
    <%@ Import Namespace="Epleservice.Common" %>
    <%@ Import Namespace="UCommerce.EntitiesV2" %>
    <%@ Import Namespace="UCommerce.Infrastructure" %>
    <%@ Import Namespace="UCommerce.Presentation.Views.Catalog" %>
    <%@ Import Namespace="UCommerce.Presentation.Views.Orders" %>
    <%@ Import Namespace="UCommerce.Security" %>
    <%@ Import Namespace="UCommerce.Security.Default" %>
    <%@ Register TagPrefix="uc" TagName="EditOrderAddress" Src="~/umbraco/ucommerce/Orders/EditOrderAddress.ascx" %>
    
    <script type="text/C#" runat="server">
    
        private const string AddressName = OrderConstants.OwnerAddressName;
    
        private bool? isEditable;
        private IEditOrderView view;
    
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
    
            view = FindOrderView();
            EditOwnerAddress.OrderAddress = view.Order.GetAddress(AddressName);
            EditOwnerAddress.IsEditable = IsEditable;
    
            view.Saving += Saving;
            view.Saved += EditOwnerAddress.View_Saved;
        }
    
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
    
            if (!IsPostBack)
                DataBind();
        }
    
        protected IEditOrderView FindOrderView()
        {
            var candidate = Parent;
            while (candidate != null && !(candidate is IEditOrderView))
                candidate = candidate.Parent;
            return (IEditOrderView)candidate;
        }
    
        protected bool IsEditable
        {
            get
            {
                if (isEditable.HasValue)
                    return isEditable.Value;
                isEditable = ObjectFactory.Instance.Resolve<ISecurityService>().CanEditPurchaseOrder(view.Order);
                if (isEditable.Value)
                    isEditable = view.Order.OrderStatus.AllowOrderEdit;
                return isEditable.Value;
            }
        }
    
        private void Saving(object sender, EntityCommandEventArgs<PurchaseOrder> e)
        {
            var modifiedAddress = EditOwnerAddress.GetModifiedOrderAddress();
            var address = e.Entity.GetAddress(AddressName);
    
            foreach (var prop in typeof (IAddress).GetProperties().Where(p => p.CanWrite))
            {
                prop.SetValue(address, prop.GetValue(modifiedAddress, null), null);
            }
        }
    
    </script>
    
    <div class="propertyPane">
        <table style="width: 100%">
            <tr>
                <th style="width: 110px! important">Produktets eier</th>
                <td>
                    <uc:EditOrderAddress runat="server" ID="EditOwnerAddress" />
                </td>
            </tr>
        </table>
    </div>
    
  • Jesper Nielsen 141 posts 498 karma points
    Mar 14, 2014 @ 09:34
    Jesper Nielsen
    0

    Hi Lars-Erik,

    Just a small observation:

    If you could inherit from "ViewEnabledControl<IEditOrderView>", the View would be readily available.

    Kind regards,

    Jesper

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Mar 14, 2014 @ 09:36
    Lars-Erik Aabech
    0

    Ah, thanks. :) Just the comment I was after.

    As long as I'm able to put it in the control directive. I believe so.

Please Sign in or register to post replies

Write your reply to:

Draft