private static void SetAliasedPropertiesIfEnabled(Document sender, string propertyName)
        {
            var property = sender.getProperty(propertyName);

            if (property == null)
            {
                return;
            }
            property.Value = url.FormatUrl(property.Value.ToString());

            foreach (var shopAlias in StoreHelper.GetAllStores())
            {
                var aliasedEnabled = sender.getProperty("enable_" + shopAlias.Alias.ToUpper());
                if (aliasedEnabled == null || aliasedEnabled.Value.ToString() != "1")
                {
                    continue;
                }

                var aliasedproperty = sender.getProperty(propertyName + "_" + shopAlias.Alias.ToUpper());

                // test == test --> overerf van global
                // test == "" --> overef van global
                if (aliasedproperty != null && aliasedproperty.Value == property.Value || aliasedproperty != null && string.IsNullOrEmpty(aliasedproperty.Value.ToString()))
                {
                    aliasedproperty.Value = url.FormatUrl(property.Value.ToString());
                }
                // test == bla --> niets doen
                else if (aliasedproperty != null && !string.IsNullOrEmpty(aliasedproperty.Value.ToString()))
                {
                    aliasedproperty.Value = url.FormatUrl(aliasedproperty.Value.ToString());
                }
            }
        }
Пример #2
0
        public IEnumerable <string> GetStoreSpecificStockStoreAliasses()
        {
            if (IO.Container.Resolve <ICMSApplication>().IsBackendUserAuthenticated)
            {
                return(StoreHelper.GetAllStores().Where(x => x.UseStoreSpecificStock).Select(s => s.Alias));
            }

            return(Enumerable.Empty <string>());
        }
Пример #3
0
        public IEnumerable <IStore> GetAllStores()
        {
            if (IO.Container.Resolve <ICMSApplication>().IsBackendUserAuthenticated)
            {
                return(StoreHelper.GetAllStores());
            }

            return(Enumerable.Empty <IStore>());
        }
        private static void DocumentBeforeSave(Document sender, SaveEventArgs e)
        {
            if (sender.ContentType.Alias.StartsWith(Store.NodeAlias))
            {
                var reg        = new Regex(@"\s*");
                var storeAlias = reg.Replace(sender.Text, "");

                sender.Text = storeAlias;
                return;
            }

            var parentId = sender.ParentId;

            if (parentId < 0)
            {
                return;
            }

            var parentDoc = new Document(sender.ParentId);

            if (parentDoc.ContentType != null && (Category.IsAlias(sender.ContentType.Alias) && parentDoc.ContentType.Alias == Catalog.CategoryRepositoryNodeAlias))
            {
                var docs = GlobalSettings.HideTopLevelNodeFromPath ? Document.GetRootDocuments().SelectMany(d => d.Children).ToArray() : Document.GetRootDocuments();

                FixRootCategoryUrlName(sender, docs, "url");

                foreach (var store in StoreHelper.GetAllStores())
                {
                    string multiStorePropertyName;
                    if (GetMultiStorePropertyName(sender, store, out multiStorePropertyName))
                    {
                        continue;
                    }
                    FixRootCategoryUrlName(sender, docs, multiStorePropertyName);
                }
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            _dlInstalledStores = new DropDownList();

            var chooseText = library.GetDictionaryItem("Choose");

            if (string.IsNullOrEmpty(chooseText))
            {
                chooseText = "Choose...";
            }

            _dlInstalledStores.Items.Add(new ListItem(chooseText, "0"));

            foreach (var store in StoreHelper.GetAllStores())
            {
                _dlInstalledStores.Items.Add(new ListItem(store.Alias, store.Id.ToString()));
            }

            if (_data.Value != null)
            {
                try
                {
                    _dlInstalledStores.SelectedValue = _data.Value.ToString();
                }
                catch
                {
                }
            }

            if (ContentTemplateContainer != null)
            {
                ContentTemplateContainer.Controls.Add(_dlInstalledStores);
            }
        }
        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!");
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Gets all stores.
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <IStore> GetAllStores()
 {
     return(StoreHelper.GetAllStores().Select(s => new BasketStore(s)));
 }
Пример #8
0
 /// <summary>
 /// Get a list of all stores
 /// </summary>
 /// <returns></returns>
 public static List <Store> GetAllStores()
 {
     return(StoreHelper.GetAllStores().ToList());
 }
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            var stores = StoreHelper.GetAllStores();

            if (!stores.Any())
            {
                return(false);
            }

            var uwebshopRequest = UwebshopRequest.Current;
            var content         = uwebshopRequest.Product ?? uwebshopRequest.Category ?? uwebshopRequest.PaymentProvider ??     // in case ResolveUwebshopEntityUrl was already called from the module
                                  IO.Container.Resolve <IUrlRewritingService>().ResolveUwebshopEntityUrl().Entity;

            if (content is PaymentProvider)
            {
                var paymentProvider = content as PaymentProvider;

                Log.Instance.LogDebug("UmbracoDefaultAfterRequestInit paymentProvider: " + paymentProvider.Name);

                new PaymentRequestHandler().HandleuWebshopPaymentRequest(paymentProvider);

                var publishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(paymentProvider.Id);
                if (publishedContent == null)
                {
                    return(false);
                }
                contentRequest.PublishedContent = publishedContent;

                SetRequestCulture(contentRequest);
                return(true);
            }

            if (content is Category)
            {
                var categoryFromUrl = content as Category;

                if (categoryFromUrl.Disabled)
                {
                    return(false);
                }

                if (Access.HasAccess(categoryFromUrl.Id, categoryFromUrl.Path, Membership.GetUser()))
                {
                    var doc = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(content.Id);
                    if (doc != null)
                    {
                        contentRequest.PublishedContent = doc;
                        var altTemplate = HttpContext.Current.Request["altTemplate"];
                        contentRequest.TrySetTemplate(altTemplate);

                        SetRequestCulture(contentRequest);
                        return(true);
                    }
                }
                else
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        contentRequest.SetRedirect(library.NiceUrl(Access.GetErrorPage(categoryFromUrl.Path)));
                    }
                    contentRequest.SetRedirect(library.NiceUrl(Access.GetLoginPage(categoryFromUrl.Path)));
                    return(true);
                }
            }

            else if (content is Product)
            {
                var productFromUrl = content as Product;
                if (productFromUrl.Disabled)
                {
                    return(false);
                }

                if (Access.HasAccess(productFromUrl.Id, productFromUrl.Path, Membership.GetUser()))
                {
                    var doc = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(content.Id);
                    if (doc != null)
                    {
                        contentRequest.PublishedContent = doc;
                        var altTemplate = HttpContext.Current.Request["altTemplate"];
                        contentRequest.TrySetTemplate(altTemplate);

                        SetRequestCulture(contentRequest);
                        return(true);
                    }
                }
                else
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        contentRequest.SetRedirect(library.NiceUrl(Access.GetErrorPage(productFromUrl.Path)));
                    }
                    contentRequest.SetRedirect(library.NiceUrl(Access.GetLoginPage(productFromUrl.Path)));
                    return(true);
                }
            }
            return(false);
        }