Exemplo n.º 1
0
        public JsonResult StoreDashboardReport()
        {
            var allOrders        = _orderService.GetOrders(0, 0, null, null, null, null, null, null, null);
            var registeredRoleId = _customerService.GetCustomerRoleBySystemName("Registered").Id;
            var model            = new StoreDashboardReportModel
            {
                ProductsCount              = _catalogSearchService.PrepareQuery(new CatalogSearchQuery()).Count().ToString("N0"),
                CategoriesCount            = _categoryService.BuildCategoriesQuery(showHidden: true).Count().ToString("N0"),
                ManufacturersCount         = _manufacturerService.GetManufacturers().Count().ToString("N0"),
                AttributesCount            = _productAttributeService.GetAllProductAttributes(0, int.MaxValue).TotalCount.ToString("N0"),
                AttributeCombinationsCount = _productService.CountAllProductVariants().ToString("N0"),
                MediaCount = _mediaService.CountFiles(new MediaSearchQuery {
                    Deleted = false
                }).ToString("N0"),
                CustomersCount = _customerService.SearchCustomers(
                    new CustomerSearchQuery
                {
                    Deleted         = false,
                    CustomerRoleIds = new int[] { registeredRoleId }
                }
                    ).TotalCount.ToString("N0"),
                OrdersCount          = allOrders.Count().ToString("N0"),
                Sales                = (allOrders.Sum(x => (decimal?)x.OrderTotal) ?? 0).ToString("C0"),
                OnlineCustomersCount = _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-15), null, 0, int.MaxValue).TotalCount.ToString("N0"),
                CartsValue           = _shoppingCartService.GetAllOpenCartSubTotal().ToString("C0"),
                WishlistsValue       = _shoppingCartService.GetAllOpenWishlistSubTotal().ToString("C0")
            };

            return(new JsonResult
            {
                Data = new { model },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 2
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var productAttributes = _productAttributeService.GetAllProductAttributes();
            var gridModel         = new GridModel <ProductAttributeModel>
            {
                Data  = productAttributes.Select(x => x.ToModel()),
                Total = productAttributes.Count()
            };

            return(View(gridModel));
        }
Exemplo n.º 3
0
        public ActionResult List(GridCommand command)
        {
            var gridModel = new GridModel <ProductAttributeModel>();

            if (_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                var productAttributes = _productAttributeService.GetAllProductAttributes();

                var data = productAttributes
                           .ForCommand(command)
                           .Select(x =>
                {
                    var model = x.ToModel();
                    return(model);
                })
                           .ToList();

                gridModel.Data  = data.PagedForCommand(command);
                gridModel.Total = data.Count;
            }
            else
            {
                gridModel.Data = Enumerable.Empty <ProductAttributeModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = gridModel
            });
        }
Exemplo n.º 4
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var productAttributes = _productAttributeService.GetAllProductAttributes();
            var data      = productAttributes.Select(x => { x.Name = x.GetLocalized(z => z.Name, _workContext.WorkingLanguage.Id); return(x); }).ToList();
            var gridModel = new GridModel <ProductAttributeModel>
            {
                Data  = data.Select(x => x.ToModel()),
                Total = productAttributes.Count()
            };

            return(View(gridModel));
        }
        // AJAX.
        public ActionResult AllProductAttributes(string label, int selectedId)
        {
            var query         = _productAttributeService.GetAllProductAttributes(0, int.MaxValue).SourceQuery;
            var pager         = new FastPager <ProductAttribute>(query, 500);
            var allAttributes = new List <dynamic>();

            while (pager.ReadNextPage(out var attributes))
            {
                foreach (var attribute in attributes)
                {
                    dynamic obj = new
                    {
                        attribute.Id,
                        attribute.DisplayOrder,
                        Name = attribute.GetLocalized(x => x.Name).Value
                    };

                    allAttributes.Add(obj);
                }
            }

            var data = allAttributes
                       .OrderBy(x => x.DisplayOrder)
                       .Select(x => new ChoiceListItem
            {
                Id       = x.Id.ToString(),
                Text     = x.Name,
                Selected = x.Id == selectedId
            })
                       .ToList();

            if (label.HasValue())
            {
                data.Insert(0, new ChoiceListItem
                {
                    Id       = "0",
                    Text     = label,
                    Selected = false
                });
            }

            return(new JsonResult {
                Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 6
0
        public IActionResult List(DataSourceRequest command)
        {
            var productAttributes = _productAttributeService
                                    .GetAllProductAttributes(command.Page - 1, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data  = productAttributes.Select(x => x.ToModel()),
                Total = productAttributes.TotalCount
            };

            return(Json(gridModel));
        }
Exemplo n.º 7
0
        // Ajax.
        public ActionResult AllProductAttributes(string label, int selectedId)
        {
            var allAttributes = new Dictionary <int, string>();

            for (var pageIndex = 0; pageIndex < 9999999; ++pageIndex)
            {
                var attributes = _productAttributeService.GetAllProductAttributes(pageIndex, 500);

                foreach (var attribute in attributes)
                {
                    allAttributes[attribute.Id] = attribute.GetLocalized(x => x.Name).Value;
                }

                if (!attributes.HasNextPage)
                {
                    break;
                }
            }

            var data = allAttributes
                       .Where(x => x.Value.HasValue())
                       .Select(x => new
            {
                id       = x.Key,
                text     = x.Value,
                selected = x.Key == selectedId
            })
                       .ToList();

            if (label.HasValue())
            {
                data.Insert(0, new { id = 0, text = label, selected = false });
            }

            return(new JsonResult {
                Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 8
0
 private void GetColorAndSizeId(ref int colorAttributeId, ref int sizeAttributeId)
 {
     foreach (var att in _productAttributeService.GetAllProductAttributes())
     {
         if (att.Name.ToUpper() == "COLOR")
         {
             colorAttributeId = att.Id;
         }
         else if (att.Name.ToUpper() == "SIZE")
         {
             sizeAttributeId = att.Id;
         }
     }
 }
Exemplo n.º 9
0
        // Ajax.
        public ActionResult AllProductAttributes(string label, int selectedId)
        {
            var attributes = _productAttributeService.GetAllProductAttributes();

            if (label.HasValue())
            {
                attributes.Insert(0, new ProductAttribute {
                    Name = label, Id = 0
                });
            }

            var query =
                from attr in attributes
                select new
            {
                id       = attr.Id.ToString(),
                text     = attr.Name,
                selected = attr.Id == selectedId
            };

            return(new JsonResult {
                Data = query.ToList(), JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 10
0
        public ActionResult Configure()
        {
            var model = new ConfigurationModel();

            model.UrlAttributeId    = _licenseSettings.UrlAttributeId;
            model.DomainAttributeId = _licenseSettings.DomainAttributeId;
            model.ProductAttributes = _productAttributeService.GetAllProductAttributes().Select(a => new SelectListItem {
                Value = a.Id.ToString(), Text = a.Name
            }).ToList();
            model.ProductAttributes.Insert(0, new SelectListItem {
                Value = "0", Text = "None"
            });
            model.LicenseTypes = LicenseType.Url.ToSelectList();

            return(View("~/Plugins/Misc.Licenses/Views/Configure.cshtml", model));
        }
Exemplo n.º 11
0
        public ActionResult List(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var productAttributes = _productAttributeService
                                    .GetAllProductAttributes(command.Page - 1, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data  = productAttributes.Select(x => x.ToModel()),
                Total = productAttributes.TotalCount
            };

            return(Json(gridModel));
        }
Exemplo n.º 12
0
        public HttpResponseMessage Get(HttpRequestMessage request, int pageIndex = 0, int pageSize = int.MaxValue)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found");
                var prodAttributes = _productAttributeService.GetAllProductAttributes(pageIndex, pageSize);
                if (prodAttributes != null)
                {
                    var gridModel = new DataSourceResult
                    {
                        Data = prodAttributes.Select(x => x.ToModel()),
                        Total = prodAttributes.TotalCount
                    };

                    response = request.CreateResponse <DataSourceResult>(HttpStatusCode.OK, gridModel);
                }
                return response;
            }));
        }
        /// <summary>
        /// Prepare paged product attribute list model
        /// </summary>
        /// <param name="searchModel">Product attribute search model</param>
        /// <returns>Product attribute list model</returns>
        public virtual ProductAttributeListModel PrepareProductAttributeListModel(ProductAttributeSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get product attributes
            var productAttributes = _productAttributeService
                                    .GetAllProductAttributes(pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new ProductAttributeListModel().PrepareToGrid(searchModel, productAttributes, () =>
            {
                //fill in model values from the entity
                return(productAttributes.Select(attribute => attribute.ToModel <ProductAttributeModel>()));
            });

            return(model);
        }
        /// <summary>
        /// Prepare paged product attribute list model
        /// </summary>
        /// <param name="searchModel">Product attribute search model</param>
        /// <returns>Product attribute list model</returns>
        public virtual ProductAttributeListModel PrepareProductAttributeListModel(ProductAttributeSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get product attributes
            var productAttributes = _productAttributeService
                                    .GetAllProductAttributes(pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new ProductAttributeListModel
            {
                //fill in model values from the entity
                Data  = productAttributes.Select(attribute => attribute.ToModel()),
                Total = productAttributes.TotalCount
            };

            return(model);
        }
Exemplo n.º 15
0
        private void InstallAttributes(CcSettings settings)
        {
            var attributes = _productAttributeService.GetAllProductAttributes();
            var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes();

            var ccIdAttribute = attributes.FirstOrDefault(x => x.Name == "CcId");

            if (ccIdAttribute == null)
            {
                ccIdAttribute = new ProductAttribute()
                {
                    Name = "CcId"
                };
                _productAttributeService.InsertProductAttribute(ccIdAttribute);
            }

            var editorDefinitionSpecificationAttribute = specificationAttributes.FirstOrDefault(x => x.Name == "CC Editor");

            if (editorDefinitionSpecificationAttribute == null)
            {
                editorDefinitionSpecificationAttribute = new SpecificationAttribute
                {
                    Name         = "CC Editor",
                    DisplayOrder = 100
                };
                _specificationAttributeService.InsertSpecificationAttribute(editorDefinitionSpecificationAttribute);
            }

            var editorDefinitionSpecificationOption = editorDefinitionSpecificationAttribute.SpecificationAttributeOptions.FirstOrDefault(x => x.Name == "CC Editor");

            if (editorDefinitionSpecificationOption == null)
            {
                editorDefinitionSpecificationOption = new SpecificationAttributeOption
                {
                    DisplayOrder             = 0,
                    Name                     = "CC Editor",
                    SpecificationAttributeId = editorDefinitionSpecificationAttribute.Id
                };
                _specificationAttributeService.InsertSpecificationAttributeOption(editorDefinitionSpecificationOption);
            }

            var editorConfigurationSpecificationAttribute = specificationAttributes.FirstOrDefault(x => x.Name == "CC EditorConfig");

            if (editorConfigurationSpecificationAttribute == null)
            {
                editorConfigurationSpecificationAttribute = new SpecificationAttribute
                {
                    Name         = "CC EditorConfig",
                    DisplayOrder = 100
                };
                _specificationAttributeService.InsertSpecificationAttribute(editorConfigurationSpecificationAttribute);
            }

            var editorConfigurationSpecificationOption = editorDefinitionSpecificationAttribute.SpecificationAttributeOptions.FirstOrDefault(x => x.Name == "CC EditorConfig");

            if (editorConfigurationSpecificationOption == null)
            {
                editorConfigurationSpecificationOption = new SpecificationAttributeOption
                {
                    DisplayOrder             = 0,
                    Name                     = "CC EditorConfig",
                    SpecificationAttributeId = editorConfigurationSpecificationAttribute.Id
                };
                _specificationAttributeService.InsertSpecificationAttributeOption(editorConfigurationSpecificationOption);
            }

            // add to settings
            settings.CcIdAttributeId = ccIdAttribute.Id;
            settings.EditorDefinitionSpecificationAttributeId    = editorDefinitionSpecificationAttribute.Id;
            settings.EditorDefinitionSpecificationOptionId       = editorDefinitionSpecificationOption.Id;
            settings.EditorConfigurationSpecificationAttributeId = editorConfigurationSpecificationAttribute.Id;
            settings.EditorConfigurationSpecificationOptionId    = editorConfigurationSpecificationOption.Id;
        }
Exemplo n.º 16
0
        public IActionResult ProductAttributes()
        {
            var customerAttr = _productAttributeService.GetAllProductAttributes().Select(x => new { Id = x.Id, Name = x.Name });

            return(Json(customerAttr));
        }
Exemplo n.º 17
0
        public IActionResult CreateProductAttrs([ModelBinder(typeof(JsonModelBinder <CustomeProductAttributesDto>))] Delta <CustomeProductAttributesDto> customeProductAttributesDtoDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }
            var list = _productAttributeService.GetAllProductAttributes().Select(l => l.Name.ToLower().Trim()).ToList();

            if (!list.Contains(customeProductAttributesDtoDelta.Dto.AttributeName.ToLower().Trim()))
            {
                var productAttribute = new ProductAttribute()
                {
                    Description = customeProductAttributesDtoDelta.Dto.Description,
                    Id          = 0,
                    Name        = customeProductAttributesDtoDelta.Dto.AttributeName
                };
                _productAttributeService.InsertProductAttribute(productAttribute);
                CustomerActivityService.InsertActivity("AddNewProductAttribute", LocalizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute);
            }
            //get Product By SKU
            var product = _productService.GetProductBySku(customeProductAttributesDtoDelta.Dto.Sku);

            if (product == null)
            {
                return(Error(HttpStatusCode.NotFound, "product", "not found"));
            }
            var attr = _productAttributeService.GetProductAttributeByAXId(customeProductAttributesDtoDelta.Dto.AttributeId);

            if (attr == null)
            {
                if (customeProductAttributesDtoDelta.Dto.Values.Count > 0)
                {
                    var prodAttr = _productAttributeService.GetProductAttributeByName(customeProductAttributesDtoDelta.Dto.AttributeName);
                    //create
                    var tempAttr = new ProductAttributeMapping()
                    {
                        AttrIdAX             = customeProductAttributesDtoDelta.Dto.AttributeId,
                        AttributeControlType = AttributeControlType.DropdownList,
                        ProductId            = product.Id,
                        ProductAttributeId   = prodAttr.Id,
                        IsRequired           = true,
                    };
                    _productAttributeService.InsertProductAttributeMapping(tempAttr);
                    //
                    foreach (var item in customeProductAttributesDtoDelta.Dto.Values)
                    {
                        _productAttributeService.InsertProductAttributeValue(new ProductAttributeValue()
                        {
                            Id = 0,
                            ProductAttributeMappingId = tempAttr.Id,
                            Name            = item.Text,
                            PriceAdjustment = item.Price,
                            DisplayOrder    = item.DisplayOrder,
                        });
                    }
                }
            }
            else
            {
                var prodAttr = _productAttributeService.GetProductAttributeByName(customeProductAttributesDtoDelta.Dto.AttributeName);
                if (customeProductAttributesDtoDelta.Dto.Values.Count == 0)
                {
                    _productAttributeService.DeleteProductAttributeMapping(attr);
                }
                else
                {
                    //edit
                    attr.ProductAttributeId = prodAttr.Id;
                    _productAttributeService.UpdateProductAttributeMapping(attr);
                    //
                    var listofValues = _productAttributeService.GetProductAttributeValues(attr.Id);
                    //delete
                    foreach (var item in listofValues)
                    {
                        _productAttributeService.DeleteProductAttributeValue(item);
                    }
                    foreach (var item in customeProductAttributesDtoDelta.Dto.Values)
                    {
                        _productAttributeService.InsertProductAttributeValue(new ProductAttributeValue()
                        {
                            Id = 0,
                            ProductAttributeMappingId = attr.Id,
                            Name            = item.Text,
                            PriceAdjustment = item.Price,
                            DisplayOrder    = item.DisplayOrder,
                        });
                    }
                }
            }

            var customeProductAttributesRootObjectDto = new CustomeProductAttributesRootObjectDto();

            customeProductAttributesRootObjectDto.ProductAttributes.Add(new CustomeProductAttributesDto()
            {
                AttributeId   = 123456,
                AttributeName = "Test",
                Description   = "Test",
                Sku           = "1200",
                Values        = new List <ValueDto>()
                {
                    new ValueDto()
                    {
                        DisplayOrder = 0,
                        Price        = 1222,
                        Text         = "Test"
                    }
                    ,
                    new ValueDto()
                    {
                        DisplayOrder = 0,
                        Price        = 1222,
                        Text         = "Test"
                    }
                }
            });

            var json = JsonFieldsSerializer.Serialize(customeProductAttributesRootObjectDto, string.Empty);

            return(new RawJsonActionResult("Done"));
        }
 public async Task<IActionResult> ProductAttributes()
 {
     var customerAttr = (await _productAttributeService.GetAllProductAttributes()).Select(x => new { Id = x.Id, Name = x.Name });
     return Json(customerAttr);
 }