Exemple #1
0
        public static umbraco.cms.businesslogic.property.Property GetMultiStoreItem(this Document document, string alias)
        {
            var originalAlias = alias;

            #region frontend

            var orderInfo = OrderHelper.GetOrder();
            if (string.IsNullOrEmpty(library.Request("id")))
            {
                if (orderInfo != null)
                {
                    alias = StoreHelper.CreateMultiStorePropertyAlias(alias, orderInfo.StoreInfo.Alias);
                }
                else
                {
                    var sAlias = StoreHelper.GetCurrentStore();
                    alias = StoreHelper.CreateMultiStorePropertyAlias(alias, sAlias.Alias);
                }
                return(document.getProperty(alias));
            }

            #endregion

            #region backend

            //var nodeId = int.Parse(library.Request("id"));
            //var orderNode = new Order(nodeId);

            var typeAlias = document.ContentType.Alias;
            var orderDoc  = document;
            if (OrderedProduct.IsAlias(orderDoc.ContentType.Alias) && !OrderedProductVariant.IsAlias(orderDoc.ContentType.Alias))
            {
                orderDoc = new Document(orderDoc.ParentId);
            }

            if (typeAlias == Order.NodeAlias || OrderedProduct.IsAlias(typeAlias) && !OrderedProductVariant.IsAlias(typeAlias))
            {
                var orderInfoDoc = OrderHelper.GetOrderInfo(Guid.Parse(orderDoc.getProperty("orderGuid").Value.ToString()));
                var store        = StoreHelper.GetByAlias(orderInfoDoc.StoreInfo.Alias);

                if (store != null)
                {
                    alias = StoreHelper.CreateMultiStorePropertyAlias(alias, store.Alias);
                }
            }

            var property = document.getProperty(alias);

            if (property == null || property.Value == null)
            {
                property = document.getProperty(originalAlias);
            }

            return(property);

            #endregion
        }
        protected void DocumentAfterPublish(Document sender, PublishEventArgs e)
        {
            // when thinking about adding something here, consider ContentOnAfterUpdateDocumentCache!

            if (sender.Level > 2)
            {
                if (sender.ContentType.Alias == Order.NodeAlias || sender.Parent != null && (OrderedProduct.IsAlias(sender.ContentType.Alias) || sender.Parent.Parent != null && OrderedProductVariant.IsAlias(sender.ContentType.Alias)))
                {
                    var orderDoc = sender.ContentType.Alias == Order.NodeAlias ? sender : (OrderedProduct.IsAlias(sender.ContentType.Alias) && !OrderedProductVariant.IsAlias(sender.ContentType.Alias) ? new Document(sender.Parent.Id) : new Document(sender.Parent.Parent.Id));

                    if (orderDoc.ContentType.Alias != Order.NodeAlias)
                    {
                        throw new Exception("There was an error in the structure of the order documents");
                    }

                    // load existing orderInfo (why..? => possibly to preserve information not represented in the umbraco documents)

                    if (string.IsNullOrEmpty(orderDoc.getProperty("orderGuid").Value.ToString()))
                    {
                        Store store    = null;
                        var   storeDoc = sender.GetAncestorDocuments().FirstOrDefault(x => x.ContentType.Alias == OrderStoreFolder.NodeAlias);

                        if (storeDoc != null)
                        {
                            store = StoreHelper.GetAllStores().FirstOrDefault(x => x.Name == storeDoc.Text);
                        }

                        if (store == null)
                        {
                            store = StoreHelper.GetAllStores().FirstOrDefault();
                        }

                        var orderInfo = OrderHelper.CreateOrder(store);
                        IO.Container.Resolve <IOrderNumberService>().GenerateAndPersistOrderNumber(orderInfo);
                        orderInfo.Status = OrderStatus.Confirmed;
                        orderInfo.Save();

                        sender.SetProperty("orderGuid", orderInfo.UniqueOrderId.ToString());
                        sender.Save();
                    }
                    else
                    {
                        var orderGuid = Guid.Parse(orderDoc.getProperty("orderGuid").Value.ToString());

                        var orderInfo = OrderHelper.GetOrderInfo(orderGuid);

                        var order = new Order(orderDoc.Id);
                        orderInfo.CustomerEmail     = order.CustomerEmail;
                        orderInfo.CustomerFirstName = order.CustomerFirstName;
                        orderInfo.CustomerLastName  = order.CustomerLastName;

                        var dictionaryCustomer = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("customer")).ToDictionary(customerProperty => customerProperty.PropertyType.Alias, customerProperty => customerProperty.Value.ToString());
                        orderInfo.AddCustomerFields(dictionaryCustomer, CustomerDatatypes.Customer);

                        var dictionaryShipping = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("shipping")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
                        orderInfo.AddCustomerFields(dictionaryShipping, CustomerDatatypes.Shipping);

                        var dictionarExtra = orderDoc.GenericProperties.Where(x => x.PropertyType.Alias.StartsWith("extra")).ToDictionary(property => property.PropertyType.Alias, property => property.Value.ToString());
                        orderInfo.AddCustomerFields(dictionarExtra, CustomerDatatypes.Extra);

                        //orderInfo.SetVATNumber(order.CustomerVATNumber); happens in AddCustomerFields
                        var orderPaidProperty = order.Document.getProperty("orderPaid");
                        if (orderPaidProperty != null && orderPaidProperty.Value != null)
                        {
                            orderInfo.Paid = orderPaidProperty.Value == "1";
                        }

                        // load data recursively from umbraco documents into order tree
                        orderInfo.OrderLines = orderDoc.Children.Select(d =>
                        {
                            var fields = d.GenericProperties.Where(x => !OrderedProduct.DefaultProperties.Contains(x.PropertyType.Alias)).ToDictionary(s => s.PropertyType.Alias, s => d.GetProperty <string>(s.PropertyType.Alias));

                            var xDoc = new XDocument(new XElement("Fields"));

                            OrderUpdatingService.AddFieldsToXDocumentBasedOnCMSDocumentType(xDoc, fields, d.ContentType.Alias);

                            var orderedProduct = new OrderedProduct(d.Id);

                            var productInfo             = new ProductInfo(orderedProduct, orderInfo);
                            productInfo.ProductVariants = d.Children.Select(cd => new ProductVariantInfo(new OrderedProductVariant(cd.Id), productInfo, productInfo.Vat)).ToList();
                            return(new OrderLine(productInfo, orderInfo)
                            {
                                _customData = xDoc
                            });
                        }).ToList();

                        // store order
                        IO.Container.Resolve <IOrderRepository>().SaveOrderInfo(orderInfo);
                    }
                    // cancel does give a warning message balloon in Umbraco.
                    //e.Cancel = true;

                    //if (sender.ContentType.Alias != Order.NodeAlias)
                    //{
                    //	orderDoc.Publish(new User(0));
                    //}

                    //if (orderDoc.ParentId != 0)
                    //{
                    BasePage.Current.ClientTools.SyncTree(sender.Parent.Path, false);
                    BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", sender.Id));
                    //}
                    //orderDoc.delete();
                    BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.success, "Order Updated!", "This order has been updated!");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Get the value based on the Store Alias
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="alias">The alias.</param>
        /// <param name="storeAlias">The store alias.</param>
        /// <returns></returns>
        public static IProperty GetMultiStoreItem(this INode node, string alias, string storeAlias = null)
        {
            var originalAlias = alias;

            if (node == null)
            {
                return(null);
            }

            #region backend

            // todo: fix backend, add inCMSbackend check?
            int id;
            if (!string.IsNullOrEmpty(library.Request("id")) && int.TryParse(library.Request("id"), out id))
            {
                var typeAlias = node.NodeTypeAlias;

                var orderNode = node;
                if (OrderedProduct.IsAlias(typeAlias) && !OrderedProductVariant.IsAlias(typeAlias))
                {
                    orderNode = orderNode.Parent;
                }

                if (typeAlias == Order.NodeAlias || OrderedProduct.IsAlias(typeAlias) && !OrderedProductVariant.IsAlias(typeAlias))
                {
                    var orderInfoDoc = OrderHelper.GetOrder(Guid.Parse(orderNode.GetProperty("orderGuid").Value));
                    alias = StoreHelper.CreateMultiStorePropertyAlias(alias, orderInfoDoc.StoreInfo.Alias);

                    var propertyDoc = node.GetProperty(alias);

                    if (propertyDoc == null || string.IsNullOrEmpty(propertyDoc.Value))
                    {
                        propertyDoc = node.GetProperty(originalAlias);
                    }

                    return(propertyDoc);
                }
            }

            #endregion

            #region frontend

            // dit gebeurt duizenden keren
            if (storeAlias == null)
            {
                storeAlias = StoreHelper.GetCurrentStore().Alias;
            }
            if (storeAlias != null)
            {
                alias = StoreHelper.CreateMultiStorePropertyAlias(alias, storeAlias);
            }

            var property = node.GetProperty(alias);

            if (property == null || string.IsNullOrEmpty(property.Value))
            {
                property = node.GetProperty(originalAlias);
            }

            return(property);

            #endregion
        }