示例#1
0
        /// <summary>
        /// 创建或更新属性组合
        /// </summary>
        /// <param name="input"></param>
        /// <param name="product"></param>
        /// <returns></returns>
        private async Task CreateOrUpdateAttributeCombination(CreateOrUpdateProductInput input, Product product)
        {
            if (input.Id == null || input.Id == 0)
            {
                product.AttributeCombinations = new Collection <ProductAttributeCombination>();
            }
            else
            {
                var existItemIds   = input.AttributeCombinations.Select(i => i.Id);
                var itemsId2Remove = product.AttributeCombinations.Where(i => !existItemIds.Contains(i.Id)).ToList();

                //删除不存在的属性
                foreach (var item in itemsId2Remove)
                {
                    item.IsDeleted = true;
                    product.AttributeCombinations.Remove(item);
                }
            }

            var displayOrder = 0;

            foreach (var combinDto in input.AttributeCombinations)
            {
                // sku去重
                if (combinDto.Sku.IsNullOrWhiteSpace())
                {
                    await IsCombinSkuExisted(input, combinDto);
                }

                ProductAttributeCombination combin = null;
                var attributesJson = JsonConvert.SerializeObject(combinDto.Attributes
                                                                 .GetAttributesJson(product, _productAttributeManager, true));

                if (input.Id != 0)
                {
                    combin = product.AttributeCombinations.FirstOrDefault(c => c.Id == combinDto.Id ||
                                                                          c.AttributesJson == attributesJson);
                }

                if (combin == null)
                {
                    combin = new ProductAttributeCombination();
                }

                combin.AttributesJson     = attributesJson;
                combin.Sku                = combinDto.Sku;
                combin.ThirdPartySku      = combinDto.ThirdPartySku;
                combin.OverriddenPrice    = combinDto.OverriddenPrice;
                combin.OverriddenGoodCost = combinDto.OverriddenGoodCost;
                combin.StockQuantity      = combinDto.StockQuantity;
                combin.DisplayOrder       = displayOrder;

                if (combin.Id == 0)
                {
                    product.AttributeCombinations.Add(combin);
                }
            }
        }
示例#2
0
 /// <summary>
 /// 删除属性组合
 /// </summary>
 /// <param name="combination"></param>
 public virtual async Task DeleteCombinationAsync(ProductAttributeCombination combination)
 {
     await ProductAttributeCombinationRepository.DeleteAsync(combination);
 }
示例#3
0
 /// <summary>
 /// 添加属性组合
 /// </summary>
 /// <param name="combination"></param>
 public virtual async Task CreateCombinationAsync(ProductAttributeCombination combination)
 {
     await ProductAttributeCombinationRepository.InsertAsync(combination);
 }