Example #1
0
        /// <summary>
        /// Prepare return request reason model
        /// </summary>
        /// <param name="model">Return request reason model</param>
        /// <param name="returnRequestReason">Return request reason</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Return request reason model</returns>
        public virtual ReturnRequestReasonModel PrepareReturnRequestReasonModel(ReturnRequestReasonModel model,
                                                                                ReturnRequestReason returnRequestReason, bool excludeProperties = false)
        {
            Action <ReturnRequestReasonLocalizedModel, int> localizedModelConfiguration = null;

            if (returnRequestReason != null)
            {
                //fill in model values from the entity
                model = model ?? returnRequestReason.ToModel();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = returnRequestReason.GetLocalized(entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #2
0
        /// <summary>
        /// Prepare customer attribute model
        /// </summary>
        /// <param name="model">Customer attribute model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Customer attribute model</returns>
        public virtual CustomerAttributeModel PrepareCustomerAttributeModel(CustomerAttributeModel model,
                                                                            CustomerAttribute customerAttribute, bool excludeProperties = false)
        {
            Action <CustomerAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (customerAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? customerAttribute.ToModel();

                //prepare nested search model
                PrepareCustomerAttributeValueSearchModel(model.CustomerAttributeValueSearchModel, customerAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = customerAttribute.GetLocalized(entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare vendor attribute model
        /// </summary>
        /// <param name="model">Vendor attribute model</param>
        /// <param name="vendorAttribute">Vendor attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Vendor attribute model</returns>
        public virtual VendorAttributeModel PrepareVendorAttributeModel(VendorAttributeModel model,
                                                                        VendorAttribute vendorAttribute, bool excludeProperties = false)
        {
            Action <VendorAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (vendorAttribute != null)
            {
                //fill in model values from the entity
                model ??= vendorAttribute.ToModel <VendorAttributeModel>();

                //prepare nested search model
                PrepareVendorAttributeValueSearchModel(model.VendorAttributeValueSearchModel, vendorAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(vendorAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare address attribute model
        /// </summary>
        /// <param name="model">Address attribute model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Address attribute model</returns>
        public virtual AddressAttributeModel PrepareAddressAttributeModel(AddressAttributeModel model,
            AddressAttribute addressAttribute, bool excludeProperties = false)
        {
            Action<AddressAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (addressAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? addressAttribute.ToModel<AddressAttributeModel>();

                //prepare nested search model
                PrepareAddressAttributeValueSearchModel(model.AddressAttributeValueSearchModel, addressAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(addressAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);

            return model;
        }
Example #5
0
        /// <summary>
        /// Prepare country model
        /// </summary>
        /// <param name="model">Country model</param>
        /// <param name="country">Country</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Country model</returns>
        public virtual CountryModel PrepareCountryModel(CountryModel model, Country country, bool excludeProperties = false)
        {
            Action <CountryLocalizedModel, int> localizedModelConfiguration = null;

            if (country != null)
            {
                //fill in model values from the entity
                model = model ?? country.ToModel <CountryModel>();

                //prepare nested search model
                PrepareStateProvinceSearchModel(model.StateProvinceSearchModel, country);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(country, entity => entity.Name, languageId, false, false);
                };
            }

            //set default values for the new model
            if (country == null)
            {
                model.Published = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #6
0
        /// <summary>
        /// Prepare shipping method model
        /// </summary>
        /// <param name="model">Shipping method model</param>
        /// <param name="shippingMethod">Shipping method</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Shipping method model</returns>
        public virtual ShippingMethodModel PrepareShippingMethodModel(ShippingMethodModel model,
                                                                      ShippingMethod shippingMethod, bool excludeProperties = false)
        {
            Action <ShippingMethodLocalizedModel, int> localizedModelConfiguration = null;

            if (shippingMethod != null)
            {
                //fill in model values from the entity
                model = model ?? shippingMethod.ToModel();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = shippingMethod.GetLocalized(entity => entity.Name, languageId, false, false);
                    locale.Description = shippingMethod.GetLocalized(entity => entity.Description, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare specification attribute model
        /// </summary>
        /// <param name="model">Specification attribute model</param>
        /// <param name="specificationAttribute">Specification attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Specification attribute model</returns>
        public virtual SpecificationAttributeModel PrepareSpecificationAttributeModel(SpecificationAttributeModel model,
                                                                                      SpecificationAttribute specificationAttribute, bool excludeProperties = false)
        {
            Action <SpecificationAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (specificationAttribute != null)
            {
                //fill in model values from the entity
                model ??= specificationAttribute.ToModel <SpecificationAttributeModel>();

                //prepare nested search models
                PrepareSpecificationAttributeOptionSearchModel(model.SpecificationAttributeOptionSearchModel, specificationAttribute);
                PrepareSpecificationAttributeProductSearchModel(model.SpecificationAttributeProductSearchModel, specificationAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(specificationAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare product attribute model
        /// </summary>
        /// <param name="model">Product attribute model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Product attribute model</returns>
        public virtual ProductAttributeModel PrepareProductAttributeModel(ProductAttributeModel model,
                                                                          ProductAttribute productAttribute, bool excludeProperties = false)
        {
            Action <ProductAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (productAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? productAttribute.ToModel <ProductAttributeModel>();

                //prepare nested search models
                PreparePredefinedProductAttributeValueSearchModel(model.PredefinedProductAttributeValueSearchModel, productAttribute);
                PrepareProductAttributeProductSearchModel(model.ProductAttributeProductSearchModel, productAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = productAttribute.GetLocalized(entity => entity.Name, languageId, false, false);
                    locale.Description = productAttribute.GetLocalized(entity => entity.Description, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare checkout attribute model
        /// </summary>
        /// <param name="model">Checkout attribute model</param>
        /// <param name="checkoutAttribute">Checkout attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Checkout attribute model</returns>
        public virtual CheckoutAttributeModel PrepareCheckoutAttributeModel(CheckoutAttributeModel model,
                                                                            CheckoutAttribute checkoutAttribute, bool excludeProperties = false)
        {
            Action <CheckoutAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (checkoutAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? checkoutAttribute.ToModel <CheckoutAttributeModel>();

                //prepare nested search model
                PrepareCheckoutAttributeValueSearchModel(model.CheckoutAttributeValueSearchModel, checkoutAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name         = _localizationService.GetLocalized(checkoutAttribute, entity => entity.Name, languageId, false, false);
                    locale.TextPrompt   = _localizationService.GetLocalized(checkoutAttribute, entity => entity.TextPrompt, languageId, false, false);
                    locale.DefaultValue = _localizationService.GetLocalized(checkoutAttribute, entity => entity.DefaultValue, languageId, false, false);
                };

                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.TaxCategoryId = checkoutAttribute.TaxCategoryId;
                }

                //prepare condition attributes model
                PrepareConditionAttributesModel(model.ConditionModel, checkoutAttribute);
            }

            //currently any checkout attribute can have condition
            model.ConditionAllowed = true;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available tax categories
            _baseAdminModelFactory.PrepareTaxCategories(model.AvailableTaxCategories);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, checkoutAttribute, excludeProperties);

            return(model);
        }
        /// <summary>
        /// Prepare category model
        /// </summary>
        /// <param name="model">Category model</param>
        /// <param name="category">Category</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Category model</returns>
        public virtual CategoryModel PrepareCategoryModel(CategoryModel model, Category category, bool excludeProperties = false)
        {
            Action <CategoryLocalizedModel, int> localizedModelConfiguration = null;

            if (category != null)
            {
                //fill in model values from the entity
                model = model ?? category.ToModel <CategoryModel>();

                //prepare nested search model
                PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(category, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(category, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(category, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(category, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(category, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName          = _urlRecordService.GetSeName(category, languageId, false, false);
                };
            }

            //set default values for the new model
            if (category == null)
            {
                model.PageSize         = _catalogSettings.DefaultCategoryPageSize;
                model.PageSizeOptions  = _catalogSettings.DefaultCategoryPageSizeOptions;
                model.Published        = true;
                model.IncludeInTopMenu = true;
                model.AllowCustomersToSelectPageSize = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available category templates
            _baseAdminModelFactory.PrepareCategoryTemplates(model.AvailableCategoryTemplates, false);

            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));

            //prepare model discounts
            var availableDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, showHidden: true);

            _discountSupportedModelFactory.PrepareModelDiscounts(model, category, availableDiscounts, excludeProperties);

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, category, excludeProperties);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, category, excludeProperties);

            return(model);
        }
Example #11
0
        /// <summary>
        /// Prepare manufacturer model
        /// </summary>
        /// <param name="model">Manufacturer model</param>
        /// <param name="manufacturer">Manufacturer</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Manufacturer model</returns>
        public virtual ManufacturerModel PrepareManufacturerModel(ManufacturerModel model,
                                                                  Manufacturer manufacturer, bool excludeProperties = false)
        {
            Action <ManufacturerLocalizedModel, int> localizedModelConfiguration = null;

            if (manufacturer != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = manufacturer.ToModel <ManufacturerModel>();
                    model.SeName = _urlRecordService.GetSeName(manufacturer, 0, true, false);
                }

                //prepare nested search model
                PrepareManufacturerProductSearchModel(model.ManufacturerProductSearchModel, manufacturer);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(manufacturer, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(manufacturer, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(manufacturer, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(manufacturer, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(manufacturer, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName          = _urlRecordService.GetSeName(manufacturer, languageId, false, false);
                };
            }

            //set default values for the new model
            if (manufacturer == null)
            {
                model.PageSize        = _catalogSettings.DefaultManufacturerPageSize;
                model.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions;
                model.Published       = true;
                model.AllowCustomersToSelectPageSize = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available manufacturer templates
            _baseAdminModelFactory.PrepareManufacturerTemplates(model.AvailableManufacturerTemplates, false);

            //prepare model discounts
            var availableDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true);

            _discountSupportedModelFactory.PrepareModelDiscounts(model, manufacturer, availableDiscounts, excludeProperties);

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, manufacturer, excludeProperties);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, manufacturer, excludeProperties);

            return(model);
        }
Example #12
0
        /// <summary>
        /// Prepare plugin model
        /// </summary>
        /// <param name="model">Plugin model</param>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Plugin model</returns>
        public virtual PluginModel PreparePluginModel(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false)
        {
            Action <PluginLocalizedModel, int> localizedModelConfiguration = null;

            if (pluginDescriptor != null)
            {
                //fill in model values from the entity
                model = model ?? pluginDescriptor.ToPluginModel(model);

                model.LogoUrl             = PluginManager.GetLogoUrl(pluginDescriptor);
                model.SelectedUserRoleIds = pluginDescriptor.LimitedToUserRoles;
                if (pluginDescriptor.Installed)
                {
                    PrepareInstalledPluginModel(model, pluginDescriptor.Instance());
                }

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    var plugin = pluginDescriptor.Instance();
                    locale.FriendlyName = _localizationService.GetLocalizedFriendlyName(plugin, languageId, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model user roles
            _aclSupportedModelFactory.PrepareModelUserRoles(model);

            return(model);
        }
Example #13
0
        /// <summary>
        /// Prepare category model
        /// </summary>
        /// <param name="model">Category model</param>
        /// <param name="category">Category</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Category model</returns>
        public virtual CompanyModel PrepareCompanyModel(CompanyModel model, Company company
                                                        , bool excludeProperties = false)
        {
            Action <CategoryLocalizedModel, int> localizedModelConfiguration = null;

            if (company != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = company.ToModel <CompanyModel>();
                    //model.SeName = _urlRecordService.GetSeName(category, 0, true, false);
                }
            }

            //set default values for the new model
            if (company == null)
            {
                model.PageSize = _catalogSettings.DefaultCategoryPageSize;
                //model.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions;
                model.Published = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #14
0
        public AiBookModelView PrepareBookNodeModel(AiBookModelView bookModelModel, int?filterByBookId)
        {
            var model = new AiBookModel();

            if (bookModelModel == null)
            {
                throw new ArgumentNullException(nameof(bookModelModel));
            }

            Action <AiBookModelLocalizedModel, int> localizedModelConfiguration = null;

            //prepare nested search models
            //Prepare Categories
            _baseAdminModelFactory.PrepareCategories(bookModelModel.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));
            if (bookModelModel.BookDirId > 0)
            {
                var bookdir = _bookdirService.GetBookDirById(bookModelModel.BookDirId);
                if (bookdir != null)
                {
                    bookModelModel.BookId = bookdir.BookID;
                }
                bookModelModel.AvailableBookDirs = SelectListHelper.GetBookDirList(_bookdirService, _workContext.CurrentCustomer, _cacheManager);
            }


            if (bookModelModel.BookId > 0)
            {
                var result = _productService.GetProductById(bookModelModel.BookId);
                if (result != null)
                {
                    if (result.ProductCategories != null)
                    {
                        bookModelModel.CateId = result.ProductCategories.FirstOrDefault().CategoryId;
                    }
                    bookModelModel.BookId         = result.Id;
                    bookModelModel.AvailableBooks = SelectListHelper.GetBookList(_productService, new List <int> {
                        bookModelModel.CateId
                    }, _workContext.CurrentCustomer, _cacheManager);
                }
            }


            localizedModelConfiguration = (locale, languageId) =>
            {
                locale.Name        = _localizationService.GetLocalized(model, entity => entity.Name, languageId, false, false);
                locale.Desc        = _localizationService.GetLocalized(model, entity => entity.Desc, languageId, false, false);
                locale.WebModelUrl = _localizationService.GetLocalized(model, entity => entity.WebModelUrl, languageId, false, false);
                locale.WebGltfUrl  = _localizationService.GetLocalized(model, entity => entity.WebGltfUrl, languageId, false, false);
                locale.WebBinUrl   = _localizationService.GetLocalized(model, entity => entity.WebBinUrl, languageId, false, false);
                locale.AbUrl       = _localizationService.GetLocalized(model, entity => entity.AbUrl, languageId, false, false);
                locale.ImgUrl      = _localizationService.GetLocalized(model, entity => entity.ImgUrl, languageId, false, false);
                locale.StrJson     = _localizationService.GetLocalized(model, entity => entity.StrJson, languageId, false, false);
                //locale.SeName = _urlRecordService.GetSeName(category, languageId, false, false);
            };


            bookModelModel.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            return(bookModelModel);
        }
        /// <summary>
        /// Prepare review type model
        /// </summary>
        /// <param name="model">Review type model</param>
        /// <param name="reviewType">Review type</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Review type model</returns>
        public virtual ReviewTypeModel PrepareReviewTypeModel(ReviewTypeModel model,
                                                              ReviewType reviewType, bool excludeProperties = false)
        {
            Action <ReviewTypeLocalizedModel, int> localizedModelConfiguration = null;

            if (reviewType != null)
            {
                //fill in model values from the entity
                model = model ?? reviewType.ToModel <ReviewTypeModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = _localizationService.GetLocalized(reviewType, entity => entity.Name, languageId, false, false);
                    locale.Description = _localizationService.GetLocalized(reviewType, entity => entity.Description, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
        /// <summary>
        /// Prepare store model
        /// </summary>
        /// <param name="model">Store model</param>
        /// <param name="store">Store</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Store model</returns>
        public virtual StoreModel PrepareStoreModel(StoreModel model, Store store, bool excludeProperties = false)
        {
            Action <StoreLocalizedModel, int> localizedModelConfiguration = null;

            if (store != null)
            {
                //fill in model values from the entity
                model = model ?? store.ToModel <StoreModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(store, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare available languages
            _baseAdminModelFactory.PrepareLanguages(model.AvailableLanguages, defaultItemText: _localizationService.GetResource("Admin.Configuration.Stores.Fields.DefaultLanguage.DefaultItemText"));

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #17
0
        /// <summary>
        /// Prepare vendor model
        /// </summary>
        /// <param name="model">Vendor model</param>
        /// <param name="vendor">Vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Vendor model</returns>
        public virtual VendorModel PrepareVendorModel(VendorModel model, Vendor vendor, bool excludeProperties = false)
        {
            Action <VendorLocalizedModel, int> localizedModelConfiguration = null;

            if (vendor != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = vendor.ToModel <VendorModel>();
                    model.SeName = _urlRecordService.GetSeName(vendor, 0, true, false);
                }

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(vendor, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(vendor, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(vendor, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(vendor, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(vendor, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName          = _urlRecordService.GetSeName(vendor, languageId, false, false);
                };

                //prepare associated customers
                PrepareAssociatedCustomerModels(model.AssociatedCustomers, vendor);

                //prepare nested search models
                PrepareVendorNoteSearchModel(model.VendorNoteSearchModel, vendor);
            }

            //set default values for the new model
            if (vendor == null)
            {
                model.PageSize = 6;
                model.Active   = true;
                model.AllowCustomersToSelectPageSize = true;
                model.PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model vendor attributes
            PrepareVendorAttributeModels(model.VendorAttributes, vendor);

            //prepare address model
            var address = _addressService.GetAddressById(vendor?.AddressId ?? 0);

            if (!excludeProperties && address != null)
            {
                model.Address = address.ToModel(model.Address);
            }
            PrepareAddressModel(model.Address, address);

            return(model);
        }
Example #18
0
        public virtual ServiceModel PrepareModel(ServiceModel m, Service e, bool excludeProperties = false)
        {
            Action <ServiceLocalizedModel, int> localizedModelConfiguration = null;

            if (e != null)
            {
                //fill in model values from the entity
                m = m ?? e.ToModel <ServiceModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = _localizationService.GetLocalized(e, entity => entity.Name, languageId, false, false);
                    locale.Description = _localizationService.GetLocalized(e, entity => entity.Description, languageId, false, false);
                };
            }

            //set default values for the new model
            if (e == null)
            {
                m.Active       = true;
                m.Deleted      = false;
                m.DisplayOrder = 0;
                m.CreatedBy    = _workContext.CurrentCustomer.Id;
                m.CreatedOnUtc = DateTime.UtcNow;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                m.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(m);
        }
Example #19
0
        /// <summary>
        /// Prepare celebrity model
        /// </summary>
        /// <param name="model">Celebrity model</param>
        /// <param name="celebrity">Celebrity</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Celebrity model</returns>
        public virtual CelebrityModel PrepareCelebrityModel(CelebrityModel model, Celebrity celebrity, bool excludeProperties = false)
        {
            Action <CelebrityLocalizedModel, int> localizedModelConfiguration = null;

            if (celebrity != null)
            {
                model = celebrity.ToModel <CelebrityModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name             = _localizationService.GetLocalized(celebrity, entity => entity.Name, languageId, false, false);
                    locale.FullDescription  = _localizationService.GetLocalized(celebrity, entity => entity.FullDescription, languageId, false, false);
                    locale.ShortDescription = _localizationService.GetLocalized(celebrity, entity => entity.ShortDescription, languageId, false, false);
                };

                model.CelebrityTags = string.Join(", ", _celebrityTagService.GetAllCelebrityTagsByCelebrityId(celebrity.Id).Select(tag => tag.Name));

                //prepare localized models
                if (!excludeProperties)
                {
                    model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
                }
                PrepareCelebrityPictureSearchModel(model.CelebrityPictureSearchModel, celebrity);
            }

            //set default values for the new model
            if (celebrity == null)
            {
            }

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, celebrity, excludeProperties);

            var celebrityTags   = _celebrityTagService.GetAllCelebrityTags();
            var celebrityTagsSb = new StringBuilder();

            celebrityTagsSb.Append("var initialCelebrityTags = [");
            for (var i = 0; i < celebrityTags.Count; i++)
            {
                var tag = celebrityTags[i];
                celebrityTagsSb.Append("'");
                celebrityTagsSb.Append(JavaScriptEncoder.Default.Encode(tag.Name));
                celebrityTagsSb.Append("'");
                if (i != celebrityTags.Count - 1)
                {
                    celebrityTagsSb.Append(",");
                }
            }
            celebrityTagsSb.Append("]");

            model.InitialCelebrityTags = celebrityTagsSb.ToString();


            return(model);
        }
        /// <summary>
        /// Prepare country model
        /// </summary>
        /// <param name="model">Country model</param>
        /// <param name="country">Country</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Country model</returns>
        public virtual CountryModel PrepareCountryModel(CountryModel model, Country country, bool excludeProperties = false)
        {
            Action <CountryLocalizedModel, int> localizedModelConfiguration = null;

            if (country != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = country.ToModel <CountryModel>();
                    model.NumberOfStates = _stateProvinceService.GetStateProvincesByCountryId(country.Id)?.Count ?? 0;
                }

                //prepare nested search model
                PrepareStateProvinceSearchModel(model.StateProvinceSearchModel, country);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(country, entity => entity.Name, languageId, false, false);
                };
            }

            //set default values for the new model
            if (country == null)
            {
                model.Published      = true;
                model.AllowsBilling  = true;
                model.AllowsShipping = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, country, excludeProperties);

            return(model);
        }
        /// <summary>
        /// Prepare message template model
        /// </summary>
        /// <param name="model">Message template model</param>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Message template model</returns>
        public virtual MessageTemplateModel PrepareMessageTemplateModel(MessageTemplateModel model,
                                                                        MessageTemplate messageTemplate, bool excludeProperties = false)
        {
            Action <MessageTemplateLocalizedModel, int> localizedModelConfiguration = null;

            if (messageTemplate != null)
            {
                //fill in model values from the entity
                model ??= messageTemplate.ToModel <MessageTemplateModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.BccEmailAddresses = _localizationService.GetLocalized(messageTemplate, entity => entity.BccEmailAddresses, languageId, false, false);
                    locale.Subject           = _localizationService.GetLocalized(messageTemplate, entity => entity.Subject, languageId, false, false);
                    locale.Body           = _localizationService.GetLocalized(messageTemplate, entity => entity.Body, languageId, false, false);
                    locale.EmailAccountId = _localizationService.GetLocalized(messageTemplate, entity => entity.EmailAccountId, languageId, false, false);

                    //prepare available email accounts
                    _baseAdminModelFactory.PrepareEmailAccounts(locale.AvailableEmailAccounts,
                                                                defaultItemText: _localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Fields.EmailAccount.Standard"));

                    //PrepareEmailAccounts only gets available accounts, we need to set the item as selected manually
                    if (locale.AvailableEmailAccounts?.FirstOrDefault(x => x.Value == locale.EmailAccountId.ToString()) is SelectListItem emailAccountListItem)
                    {
                        emailAccountListItem.Selected = true;
                    }
                };
            }

            model.SendImmediately     = !model.DelayBeforeSend.HasValue;
            model.HasAttachedDownload = model.AttachedDownloadId > 0;

            var allowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens(_messageTokenProvider.GetTokenGroups(messageTemplate)));

            model.AllowedTokens = $"{allowedTokens}{Environment.NewLine}{Environment.NewLine}" +
                                  $"{_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Tokens.ConditionalStatement")}{Environment.NewLine}";

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available email accounts
            _baseAdminModelFactory.PrepareEmailAccounts(model.AvailableEmailAccounts);

            //prepare available stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, messageTemplate, excludeProperties);

            return(model);
        }
Example #22
0
        /// <summary>
        /// Prepare topic model
        /// </summary>
        /// <param name="model">Topic model</param>
        /// <param name="topic">Topic</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Topic model</returns>
        public virtual TopicModel PrepareTopicModel(TopicModel model, Topic topic, bool excludeProperties = false)
        {
            Action <TopicLocalizedModel, int> localizedModelConfiguration = null;

            if (topic != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = topic.ToModel <TopicModel>();
                    model.SeName = _urlRecordService.GetSeName(topic, 0, true, false);
                }

                model.Url = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext)
                            .RouteUrl("Topic", new { SeName = _urlRecordService.GetSeName(topic) }, _webHelper.CurrentRequestProtocol);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Title           = _localizationService.GetLocalized(topic, entity => entity.Title, languageId, false, false);
                    locale.Body            = _localizationService.GetLocalized(topic, entity => entity.Body, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(topic, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(topic, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(topic, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName          = _urlRecordService.GetSeName(topic, languageId, false, false);
                };
            }

            //set default values for the new model
            if (topic == null)
            {
                model.DisplayOrder = 1;
                model.Published    = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available topic templates
            _baseAdminModelFactory.PrepareTopicTemplates(model.AvailableTopicTemplates, false);

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, topic, excludeProperties);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, topic, excludeProperties);

            return(model);
        }
Example #23
0
        public virtual TopicCategoryModel PrepareTopicCategoryModel(TopicCategoryModel model, TopicCategory topic, bool excludeProperties = false)
        {
            Action <TopicCategoryLocalizedModel, int> localizedModelConfiguration = null;

            if (topic != null)
            {
                //fill in model values from the entity
                model = model ?? topic.ToModel <TopicCategoryModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(topic, entity => entity.Name, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(topic, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(topic, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(topic, entity => entity.MetaTitle, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            model.TopicCategories.Add(new TopicCategory()
            {
                Id = 0, Name = "ROOT"
            });
            _topicService
            .GetAllTopicCategories()
            .Where(x => x.Id != topic?.Id)
            .ToList()
            .ForEach(x => model.TopicCategories.Add(x));

            return(model);
        }
Example #24
0
        public virtual ContractAttributeModel PrepareContractAttributeModel(ContractAttributeModel model,
                                                                            ContractAttribute contractAttribute, bool excludeProperties = false)
        {
            Action <ContractAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (contractAttribute != null)
            {
                model = model ?? contractAttribute.ToModel <ContractAttributeModel>();

                PrepareContractAttributeValueSearchModel(model.ContractAttributeValueSearchModel, contractAttribute);

                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(contractAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #25
0
        public virtual DepartmentModel PrepareModel(DepartmentModel model, Department service, bool excludeProperties = false)
        {
            Action <DepartmentLocalizedModel, int> localizedModelConfiguration = null;

            if (service != null)
            {
                //fill in model values from the entity
                model = model ?? service.ToModel <DepartmentModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = _localizationService.GetLocalized(service, entity => entity.Name, languageId, false, false);
                    locale.Description = _localizationService.GetLocalized(service, entity => entity.Description, languageId, false, false);
                    locale.Address     = _localizationService.GetLocalized(service, entity => entity.Address, languageId, false, false);
                };
            }

            //set default values for the new model
            if (service == null)
            {
                model.Active       = true;
                model.Deleted      = false;
                model.CreatedBy    = _workContext.CurrentCustomer.Id;
                model.CreatedOnUtc = DateTime.UtcNow;
                PrepareDepartmentTemplatesForCreate(model.DepartmentListTemplates, false, null);
            }
            else
            {
                //prepare available category templates
                PrepareDepartmentTemplatesForEdit(model.DepartmentListTemplates, false, null);

                model.DepartmentListTemplates = model.DepartmentListTemplates.GroupBy(s => s.Value, i => i, (k, item) => new SelectListItem
                {
                    Text     = item.First().Text,
                    Value    = k,
                    Selected = item.First().Selected
                }).ToList();
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Example #26
0
        /// <summary>
        /// Prepare slide model
        /// </summary>
        /// <param name="model">Slide model</param>
        /// <param name="slide">Slide entity</param>
        /// <param name="excludeProperties">Prepare localized values or not</param>
        /// <returns>Slide model</returns>
        public virtual SlideModel PrepareSlideModel(SlideModel model, Slide slide, bool excludeProperties = false)
        {
            Action <SlideLocalizedModel, int> localizedModelConfiguration = null;

            if (slide != null)
            {
                model.Id           = slide.Id;
                model.Hyperlink    = slide.HyperlinkAddress;
                model.PictureId    = slide.PictureId.GetValueOrDefault(0);
                model.Description  = slide.Description;
                model.StartDateUtc = slide.StartDateUtc;
                model.EndDateUtc   = slide.EndDateUtc;
                model.Published    = slide.Published;

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.PictureId   = _localizationService.GetLocalized(slide, x => x.PictureId, languageId, false, false).GetValueOrDefault(0);
                    locale.Description = _localizationService.GetLocalized(slide, entity => entity.Description, languageId, false, false);
                    locale.Hyperlink   = _localizationService.GetLocalized(slide, entity => entity.HyperlinkAddress, languageId, false, false);
                };
            }

            //prepare slide store mappings
            PrepareStoreMapping(model, slide);

            //prepare slide ACL
            PrepareAclModel(model, slide, false);

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model widget zone search
            model.WidgetZoneSearchModel.SetGridPageSize();

            return(model);
        }
        /// <summary>
        /// Prepare plugin model
        /// </summary>
        /// <param name="model">Plugin model</param>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Plugin model</returns>
        public virtual PluginModel PreparePluginModel(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false)
        {
            Action <PluginLocalizedModel, int> localizedModelConfiguration = null;

            if (pluginDescriptor != null)
            {
                //fill in model values from the entity
                model ??= pluginDescriptor.ToPluginModel(model);

                model.LogoUrl                 = _pluginService.GetPluginLogoUrl(pluginDescriptor);
                model.SelectedStoreIds        = pluginDescriptor.LimitedToStores;
                model.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles;
                var plugin = pluginDescriptor.Instance <IPlugin>();
                if (pluginDescriptor.Installed)
                {
                    PrepareInstalledPluginModel(model, plugin);
                }

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.FriendlyName = _localizationService.GetLocalizedFriendlyName(plugin, languageId, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model);

            //prepare available stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model);

            return(model);
        }
Example #28
0
        /// <summary>
        /// Prepare currency model
        /// </summary>
        /// <param name="model">Currency model</param>
        /// <param name="currency">Currency</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Currency model</returns>
        public virtual CurrencyModel PrepareCurrencyModel(CurrencyModel model, Currency currency, bool excludeProperties = false)
        {
            Action <CurrencyLocalizedModel, int> localizedModelConfiguration = null;

            if (currency != null)
            {
                //fill in model values from the entity
                model = model ?? currency.ToModel <CurrencyModel>();

                //convert dates to the user time
                model.CreatedOn = _dateTimeHelper.ConvertToUserTime(currency.CreatedOnUtc, DateTimeKind.Utc);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(currency, entity => entity.Name, languageId, false, false);
                };
            }

            //set default values for the new model
            if (currency == null)
            {
                model.Published = true;
                model.Rate      = 1;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, currency, excludeProperties);

            return(model);
        }
Example #29
0
        public BookDirModel PrepareBookDirModel(BookDirModel model, BookDir bookdir = null, bool excludeProperties = false)
        {
            Action <BookDirLocalizedModel, int> localizedModelConfiguration = null;

            if (bookdir != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = bookdir.ToModel <BookDirModel>();
                    model.SeName = _urlRecordService.GetSeName(bookdir, 0, true, false);
                }
                var result = _productService.GetProductById(bookdir.BookID);
                if (result != null)
                {
                    if (result.ProductCategories != null)
                    {
                        model.CategryID = result.ProductCategories.FirstOrDefault().CategoryId;
                    }
                    model.BookID = result.Id;
                    var products = _productService.SearchProducts(showHidden: true,
                                                                  categoryIds: new List <int>()
                    {
                        model.CategryID
                    },
                                                                  manufacturerId: 0,
                                                                  storeId: 0,
                                                                  vendorId: 0,
                                                                  warehouseId: 0,
                                                                  productType: null,
                                                                  keywords: null,
                                                                  pageIndex: 0,
                                                                  pageSize: int.MaxValue);

                    // model.BookList = products.ToList().ToSelect<Product>()
                }
                //prepare nested search model

                // PrepareBookDirSearchModel()

                //  PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(bookdir, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(bookdir, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(bookdir, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(bookdir, entity => entity.MetaDescription, languageId, false, false);
                    //locale.MetaTitle = _localizationService.GetLocalized(category, entity => entity.MetaTitle, languageId, false, false);
                    //locale.SeName = _urlRecordService.GetSeName(category, languageId, false, false);
                };
            }

            //set default values for the new model
            if (bookdir == null)
            {
                if (model == null)
                {
                    model = new BookDirModel();
                }

                //model.PageSize = _catalogSettings.DefaultCategoryPageSize;
                // model.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions;
                model.Published = true;
                //  model.IncludeInTopMenu = true;
                model.AllowCustomersToSelectPageSize = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available category templates
            // _baseAdminModelFactory.PrepareCategoryTemplates(model.AvailableCategoryTemplates, false);
            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));
            //prepare model discounts
            // var availableDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, showHidden: true);
            //_discountSupportedModelFactory.PrepareModelDiscounts(model, category, availableDiscounts, excludeProperties);
            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, bookdir, excludeProperties);
            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, bookdir, excludeProperties);
            return(model);
        }
Example #30
0
        /// <summary>
        /// Prepare product model
        /// </summary>
        /// <param name="model">Product model</param>
        /// <param name="product">Product</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Product model</returns>
        public virtual ProductModel PrepareProductModel(ProductModel model, Product product, bool excludeProperties = false)
        {
            Action <ProductLocalizedModel, int> localizedModelConfiguration = null;

            if (product != null)
            {
                //fill in model values from the entity
                model = model ?? product.ToModel <ProductModel>();

                var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId);
                if (parentGroupedProduct != null)
                {
                    model.AssociatedToProductId   = product.ParentGroupedProductId;
                    model.AssociatedToProductName = parentGroupedProduct.Name;
                }

                model.CreatedOn   = _dateTimeHelper.ConvertToUserTime(product.CreatedOnUtc, DateTimeKind.Utc);
                model.UpdatedOn   = _dateTimeHelper.ConvertToUserTime(product.UpdatedOnUtc, DateTimeKind.Utc);
                model.ProductTags = string.Join(", ", _productTagService.GetAllProductTagsByProductId(product.Id).Select(tag => tag.Name));

                if (!excludeProperties)
                {
                    model.SelectedCategoryIds = _categoryService.GetProductCategoriesByProductId(product.Id, true)
                                                .Select(productCategory => productCategory.CategoryId).ToList();
                }

                //prepare copy product model
                PrepareCopyProductModel(model.CopyProductModel, product);


                //prepare nested search model
                PrepareRelatedProductSearchModel(model.RelatedProductSearchModel, product);
                PrepareAssociatedProductSearchModel(model.AssociatedProductSearchModel, product);
                PrepareProductPictureSearchModel(model.ProductPictureSearchModel, product);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name             = _localizationService.GetLocalized(product, entity => entity.Name, languageId, false, false);
                    locale.FullDescription  = _localizationService.GetLocalized(product, entity => entity.FullDescription, languageId, false, false);
                    locale.ShortDescription = _localizationService.GetLocalized(product, entity => entity.ShortDescription, languageId, false, false);
                    locale.MetaKeywords     = _localizationService.GetLocalized(product, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription  = _localizationService.GetLocalized(product, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle        = _localizationService.GetLocalized(product, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName           = _urlRecordService.GetSeName(product, languageId, false, false);
                };
            }

            //set default values for the new model
            if (product == null)
            {
                model.AllowCustomerReviews = true;
                model.Published            = true;
                model.VisibleIndividually  = true;
            }

            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare editor settings
            model.ProductEditorSettingsModel = _settingModelFactory.PrepareProductEditorSettingsModel();

            //prepare available product templates
            _baseAdminModelFactory.PrepareProductTemplates(model.AvailableProductTemplates, false);

            //prepare available product types
            var productTemplates = _productTemplateService.GetAllProductTemplates();

            foreach (var productType in Enum.GetValues(typeof(ProductType)).OfType <ProductType>())
            {
                model.ProductsTypesSupportedByProductTemplates.Add((int)productType, new List <SelectListItem>());
                foreach (var template in productTemplates)
                {
                    var list = (IList <int>)TypeDescriptor.GetConverter(typeof(List <int>)).ConvertFrom(template.IgnoredProductTypes) ?? new List <int>();
                    if (string.IsNullOrEmpty(template.IgnoredProductTypes) || !list.Contains((int)productType))
                    {
                        model.ProductsTypesSupportedByProductTemplates[(int)productType].Add(new SelectListItem
                        {
                            Text  = template.Name,
                            Value = template.Id.ToString()
                        });
                    }
                }
            }


            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(model.AvailableVendors,
                                                  defaultItemText: _localizationService.GetResource("Admin.Catalog.Products.Fields.Vendor.None"));

            //prepare model categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories, false);
            foreach (var categoryItem in model.AvailableCategories)
            {
                categoryItem.Selected = int.TryParse(categoryItem.Value, out var categoryId) &&
                                        model.SelectedCategoryIds.Contains(categoryId);
            }

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, product, excludeProperties);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, product, excludeProperties);

            return(model);
        }