Exemplo n.º 1
0
        private async Task <int> ProcessFrameAsync(OrderItem orderItem, int lineNumber, List <YahooDetailRow> result)
        {
            var frame = orderItem.GetFrame();

            if (frame != null)
            {
                var size = orderItem.GetMattressSize();
                var amf  = _abcMattressFrameService.GetAbcMattressFramesBySize(size)
                           .Where(p => p.Name == frame)
                           .FirstOrDefault();
                result.Add(new YahooDetailRow(
                               _settings.OrderIdPrefix,
                               orderItem,
                               lineNumber,
                               "", // no item ID associated
                               amf.ItemNo,
                               amf.Price,
                               frame,
                               "", // no url
                               await GetPickupStoreAsync(orderItem)
                               ));
                lineNumber++;
            }

            return(lineNumber);
        }
Exemplo n.º 2
0
        private async Task MergeFramesAsync(AbcMattressModel model, ProductAttribute pa, Product product)
        {
            var pam = (await _productAttributeService.GetProductAttributeMappingsByProductIdAsync(product.Id))
                      .Where(pam => pam.ProductAttributeId == pa.Id)
                      .FirstOrDefault();
            var abcMattressEntry = _abcMattressEntryService.GetAbcMattressEntriesByModelId(model.Id)
                                   .Where(ame => pa.Name == $"Frame ({ame.Size})")
                                   .FirstOrDefault();

            if (abcMattressEntry == null)
            {
                return;
            }

            var frames = _abcMattressFrameService.GetAbcMattressFramesBySize(abcMattressEntry.Size);

            if (pam == null && frames.Any())
            {
                var sizeAttrs = await GetSizeAttributesAsync(product, abcMattressEntry);

                pam = new ProductAttributeMapping()
                {
                    ProductId             = product.Id,
                    ProductAttributeId    = pa.Id,
                    IsRequired            = false,
                    AttributeControlType  = AttributeControlType.DropdownList,
                    DisplayOrder          = 30,
                    TextPrompt            = "Frame",
                    ConditionAttributeXml = $"<Attributes><ProductAttribute ID=\"{sizeAttrs.pam.Id}\"><ProductAttributeValue><Value>{sizeAttrs.pav.Id}</Value></ProductAttributeValue></ProductAttribute></Attributes>"
                };
                await _productAttributeService.InsertProductAttributeMappingAsync(pam);
            }
            else if (pam != null && !frames.Any())
            {
                await _productAttributeService.DeleteProductAttributeMappingAsync(pam);
            }
            else if (pam != null)
            {
                await UpdatePamAsync(product, pam, abcMattressEntry);
            }

            if (!frames.Any())
            {
                return;
            }

            var existingFrames = (await _productAttributeService.GetProductAttributeValuesAsync(pam.Id))
                                 .Where(pav =>
                                        pav.ProductAttributeMappingId == pam.Id
                                        );
            var newFrames = frames.Select(np => np.ToProductAttributeValue(
                                              pam.Id
                                              )).OrderBy(f => f.PriceAdjustment).ToList();

            ApplyDisplayOrder(newFrames);

            var toBeDeleted = existingFrames
                              .Where(e => !newFrames.Any(n => n.Name == e.Name && n.DisplayOrder == e.DisplayOrder &&
                                                         n.PriceAdjustment == e.PriceAdjustment));
            var toBeInserted = newFrames
                               .Where(n => !existingFrames.Any(e => n.Name == e.Name && n.DisplayOrder == e.DisplayOrder &&
                                                               n.PriceAdjustment == e.PriceAdjustment));

            toBeInserted.ToList().ForEach(async n => await _productAttributeService.InsertProductAttributeValueAsync(n));
            toBeDeleted.ToList().ForEach(async e => await _productAttributeService.DeleteProductAttributeValueAsync(e));
        }