Esempio n. 1
0
        public virtual CustomerOrder GetById(string orderId, CustomerOrderResponseGroup respGroup)
        {
            CustomerOrder retVal = null;

            using (var repository = _repositoryFactory())
            {
                var orderEntity = repository.GetCustomerOrderById(orderId, respGroup);
                if (orderEntity != null)
                {
                    retVal = orderEntity.ToCoreModel(_shippingMethodsService.GetAllShippingMethods(), _paymentMethodsService.GetAllPaymentMethods());

                    if ((respGroup & CustomerOrderResponseGroup.WithProducts) == CustomerOrderResponseGroup.WithProducts)
                    {
                        var productIds = retVal.Items.Select(x => x.ProductId).ToArray();
                        var products   = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                        foreach (var lineItem in retVal.Items)
                        {
                            var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId);
                            if (product != null)
                            {
                                lineItem.Product = product;
                            }
                        }
                    }
                }
            }

            _dynamicPropertyService.LoadDynamicPropertyValues(retVal);

            _eventPublisher.Publish(new OrderChangeEvent(EntryState.Unchanged, retVal, retVal));
            return(retVal);
        }
Esempio n. 2
0
        public coreModel.Contact GetById(string id)
        {
            coreModel.Contact retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetContactById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal != null)
            {
                //Load dynamic properties for contact
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);

                //Load all security accounts associated with this contact
                var result = Task.Run(() => _securityService.SearchUsersAsync(new UserSearchRequest {
                    MemberId = retVal.Id, TakeCount = int.MaxValue
                })).Result;
                retVal.SecurityAccounts = result.Users.ToList();
            }

            return(retVal);
        }
Esempio n. 3
0
        public coreModel.Store[] GetByIds(string[] ids)
        {
            var retVal = new List <coreModel.Store>();

            using (var repository = _repositoryFactory())
            {
                var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList();
                var dbStores           = repository.GetStoresByIds(ids);
                foreach (var dbStore in dbStores)
                {
                    //Load original typed shipping method and populate it  personalized information from db
                    var store = dbStore.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders());

                    store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId);
                    store.FulfillmentCenter        = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId);
                    //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues
                    store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store");
                    _settingManager.LoadEntitySettingsValues(store);
                    _dynamicPropertyService.LoadDynamicPropertyValues(store);
                    retVal.Add(store);
                }
            }
            _commerceService.LoadSeoForObjects(retVal.ToArray());
            return(retVal.ToArray());
        }
        public coreModel.Store GetById(string id)
        {
            var cacheKey = CacheKey.Create("StoreModule", "GetById", id);

            return(_cacheManager.Get(cacheKey, () =>
            {
                coreModel.Store retVal = null;
                using (var repository = _repositoryFactory())
                {
                    var entity = repository.GetStoreById(id);

                    if (entity != null)
                    {
                        //Load original typed shipping method and populate it  personalized information from db
                        retVal = entity.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders());

                        var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList();
                        retVal.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.ReturnsFulfillmentCenterId);
                        retVal.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.FulfillmentCenterId);
                        retVal.SeoInfos = _commerceService.GetObjectsSeo(new[] { id }).ToList();

                        _settingManager.LoadEntitySettingsValues(retVal);
                        _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
                    }
                }
                return retVal;
            }));
        }
        public virtual ShoppingCart[] GetByIds(string[] cartIds, string responseGroup = null)
        {
            var retVal = new List <ShoppingCart>();

            using (var repository = _repositoryFactory())
            {
                //Disable DBContext change tracking for better performance
                repository.DisableChangesTracking();

                var cartEntities = repository.GetShoppingCartsByIds(cartIds);
                foreach (var cartEntity in cartEntities)
                {
                    var cart = cartEntity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance());
                    //Calculate totals only for full responseGroup
                    if (responseGroup == null)
                    {
                        _totalsCalculator.CalculateTotals(cart);
                    }
                    retVal.Add(cart);
                }
            }

            _dynamicPropertyService.LoadDynamicPropertyValues(retVal.ToArray <IHasDynamicProperties>());

            return(retVal.ToArray());
        }
Esempio n. 6
0
        public ShoppingCart GetById(string cartId)
        {
            ShoppingCart retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetShoppingCartById(cartId);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();

                    var productIds = retVal.Items.Select(x => x.ProductId).ToArray();
                    var products   = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                    foreach (var lineItem in retVal.Items)
                    {
                        var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId);
                        if (product != null)
                        {
                            lineItem.Product = product;
                        }
                    }

                    _eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Unchanged, retVal, retVal));
                }
            }

            if (retVal != null)
            {
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
            }

            return(retVal);
        }
Esempio n. 7
0
        public Store[] GetByIds(string[] ids)
        {
            var stores = new List <Store>();

            using (var repository = _repositoryFactory())
            {
                var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList();
                var dbStores           = repository.GetStoresByIds(ids);
                foreach (var dbStore in dbStores)
                {
                    var store = AbstractTypeFactory <Store> .TryCreateInstance();

                    dbStore.ToModel(store);

                    //Return all registered methods with store settings
                    store.PaymentMethods = _paymentService.GetAllPaymentMethods();
                    foreach (var paymentMethod in store.PaymentMethods)
                    {
                        var dbStoredPaymentMethod = dbStore.PaymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(paymentMethod.Code));
                        if (dbStoredPaymentMethod != null)
                        {
                            dbStoredPaymentMethod.ToModel(paymentMethod);
                        }
                    }
                    store.ShippingMethods = _shippingService.GetAllShippingMethods();
                    foreach (var shippingMethod in store.ShippingMethods)
                    {
                        var dbStoredShippingMethod = dbStore.ShippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shippingMethod.Code));
                        if (dbStoredShippingMethod != null)
                        {
                            dbStoredShippingMethod.ToModel(shippingMethod);
                        }
                    }
                    store.TaxProviders = _taxService.GetAllTaxProviders();
                    foreach (var taxProvider in store.TaxProviders)
                    {
                        var dbStoredTaxProvider = dbStore.TaxProviders.FirstOrDefault(x => x.Code.EqualsInvariant(taxProvider.Code));
                        if (dbStoredTaxProvider != null)
                        {
                            dbStoredTaxProvider.ToModel(taxProvider);
                        }
                    }

                    store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId);
                    store.FulfillmentCenter        = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId);
                    //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues
                    store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store");
                    _settingManager.LoadEntitySettingsValues(store);
                    stores.Add(store);
                }
            }

            var result = stores.ToArray();

            _dynamicPropertyService.LoadDynamicPropertyValues(result);
            _commerceService.LoadSeoForObjects(result);
            return(result);
        }
Esempio n. 8
0
 public IEnumerable <QuoteRequest> GetByIds(params string[] ids)
 {
     using (var repository = _repositoryFactory())
     {
         var retVal = repository.GetQuoteRequestByIds(ids).Select(x => x.ToCoreModel()).ToArray();
         foreach (var quote in retVal)
         {
             _dynamicPropertyService.LoadDynamicPropertyValues(quote);
             _changeLogService.LoadChangeLogs(quote);
             _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Unchanged, quote, quote));
         }
         return(retVal);
     }
 }
Esempio n. 9
0
        public DynamicContentItem[] GetContentItemsByIds(string[] ids)
        {
            DynamicContentItem[] retVal = null;
            using (var repository = _repositoryFactory())
            {
                retVal = repository.GetContentItemsByIds(ids).Select(x => x.ToModel(AbstractTypeFactory <DynamicContentItem> .TryCreateInstance())).ToArray();
            }

            if (retVal != null)
            {
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
            }

            return(retVal);
        }
Esempio n. 10
0
        public Member[] GetByIds(params string[] memberIds)
        {
            var retVal = new List <Member>();

            using (var repository = _repositoryFactory())
            {
                var dbMembers = repository.GetMembersByIds(memberIds);
                retVal.AddRange(dbMembers.Select(x => ConvertToMember(x)));
            }

            foreach (var member in retVal)
            {
                //Load dynamic properties for member
                _dynamicPropertyService.LoadDynamicPropertyValues(member);
            }

            return(retVal.ToArray());
        }
        public coreModel.DynamicContentItem GetContentItemById(string id)
        {
            coreModel.DynamicContentItem retVal = null;
            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetContentItemById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal != null)
            {
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
            }

            return(retVal);
        }
Esempio n. 12
0
        public coreModel.Organization GetById(string id)
        {
            coreModel.Organization retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetOrganizationById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal != null)
            {
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
            }

            return(retVal);
        }