예제 #1
0
        private ProductAttributeValueDto PrepareProductAttributeValueDto(ProductAttributeValue productAttributeValue, Product product)
        {
            ProductAttributeValueDto productAttributeValueDto = null;

            if (productAttributeValue != null)
            {
                productAttributeValueDto = productAttributeValue.ToDto();
                if (productAttributeValue.ImageSquaresPictureId > 0)
                {
                    Picture  imageSquaresPicture = _pictureService.GetPictureById(productAttributeValue.ImageSquaresPictureId);
                    ImageDto imageDto            = PrepareImageDto(imageSquaresPicture);
                    productAttributeValueDto.ImageSquaresImage = imageDto;
                }

                if (productAttributeValue.PictureId > 0)
                {
                    // make sure that the picture is mapped to the product
                    // This is needed since if you delete the product picture mapping from the nopCommerce administrationthe
                    // then the attribute value is not updated and it will point to a picture that has been deleted
                    var productPicture = product.ProductPictures.FirstOrDefault(pp => pp.PictureId == productAttributeValue.PictureId);
                    if (productPicture != null)
                    {
                        productAttributeValueDto.ProductPictureId = productPicture.Id;
                    }
                }
            }

            return(productAttributeValueDto);
        }
예제 #2
0
        private ProductAttributeValueDto PrepareProductAttributeValueDto(ProductAttributeValue productAttributeValue)
        {
            ProductAttributeValueDto productAttributeValueDto = null;

            if (productAttributeValue != null)
            {
                productAttributeValueDto = new ProductAttributeValueDto
                {
                    Id                   = productAttributeValue.Id,
                    Cost                 = productAttributeValue.Cost,
                    Name                 = productAttributeValue.Name,
                    Quantity             = productAttributeValue.Quantity,
                    DisplayOrder         = productAttributeValue.DisplayOrder,
                    PictureId            = productAttributeValue.PictureId,
                    PriceAdjustment      = productAttributeValue.PriceAdjustment,
                    WeightAdjustment     = productAttributeValue.WeightAdjustment,
                    AssociatedProductId  = productAttributeValue.AssociatedProductId,
                    ColorSquaresRgb      = productAttributeValue.ColorSquaresRgb,
                    IsPreSelected        = productAttributeValue.IsPreSelected,
                    AttributeValueTypeId = productAttributeValue.AttributeValueTypeId,
                };
            }

            return(productAttributeValueDto);
        }
예제 #3
0
        /// <summary>
        /// 初始化属性组合
        /// </summary>
        /// <param name="product"></param>
        /// <param name="createOrUpdateProduct"></param>
        /// <returns></returns>
        private async Task <List <AttributeCombinationDto> > PrepareProductAttributeCombination(Product product, bool createOrUpdateProduct = true)
        {
            var combinDtoList = new List <AttributeCombinationDto>();

            var combins = product.AttributeCombinations.OrderBy(c => c.DisplayOrder).ToList();

            foreach (var combination in combins)
            {
                var combinationDto = ObjectMapper.Map <AttributeCombinationDto>(combination);

                var jsonAttributeList = JsonConvert.DeserializeObject <List <JsonProductAttribute> >(combination.AttributesJson);

                foreach (var jsonAttribute in jsonAttributeList)
                {
                    var atributeDto = new ProductAttributeDto();

                    var attribute = await _productAttributeManager.GetByIdAsync(jsonAttribute.AttributeId);

                    atributeDto.Id     = jsonAttribute.AttributeId;
                    atributeDto.Name   = attribute.Name;
                    atributeDto.Values = jsonAttribute.AttributeValues.Select(value =>
                    {
                        var valueDto = new ProductAttributeValueDto();

                        var attributeValue = _productAttributeManager.FindValueById(value.AttributeValueId);
                        if (attributeValue == null)
                        {
                            valueDto.Name = _productAttributeManager.GetPredefinedValueById(value.AttributeValueId).Name;
                        }
                        else
                        {
                            valueDto.Name = attributeValue.Name;
                        }

                        valueDto.Id = createOrUpdateProduct ? attributeValue.PredefinedProductAttributeValueId : attributeValue.Id;

                        return(valueDto);
                    }).ToList();
                    combinationDto.Attributes.Add(atributeDto);
                }

                combinDtoList.Add(combinationDto);
            }

            return(combinDtoList);
        }
        /// <summary>
        /// 初始化子订单商品属性
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private async Task <List <ProductAttributeDto> > PrepareOrderItemAttribute(OrderItem item)
        {
            var attributes = new List <ProductAttributeDto>();

            if (item.AttributesJson.IsNullOrWhiteSpace())
            {
                return(attributes);
            }

            var jsonAttributeList = JsonConvert.DeserializeObject <List <JsonProductAttribute> >(item.AttributesJson);

            foreach (var jsonAttribute in jsonAttributeList)
            {
                var atributeDto = new ProductAttributeDto();

                var attribute = await _productAttributeManager.GetByIdAsync(jsonAttribute.AttributeId);

                atributeDto.Id     = jsonAttribute.AttributeId;
                atributeDto.Name   = attribute.Name;
                atributeDto.Values = jsonAttribute.AttributeValues.Select(value =>
                {
                    var valueDto = new ProductAttributeValueDto();

                    var attributeValue = _productAttributeManager.FindValueById(value.AttributeValueId);
                    if (attributeValue == null)
                    {
                        valueDto.Name = _productAttributeManager.GetPredefinedValueById(value.AttributeValueId).Name;
                    }
                    else
                    {
                        valueDto.Name = attributeValue.Name;
                    }

                    valueDto.Id         = attributeValue.Id;
                    valueDto.PictureUrl = _pictureManager.GetPictureUrl(attributeValue.PictureId);
                    return(valueDto);
                }).ToList();
                attributes.Add(atributeDto);
            }

            return(attributes);
        }