protected virtual TProduct BaseMap(ProductContent source)
        {
            var imageUrl            = source.CommerceMediaCollection.FirstOrDefault()?.AssetLink.GetUrl();
            var thumbnail           = UrlHelper.GetAsThumbnailUrl(imageUrl);
            var variantQuantity     = GetTotalInventoryByEntry(source.Code);
            var configurableOptions = GetProductConfigurableOptions(source).ToList();

            var productVariations = source.GetVariants();

            var productPrice = PriceService.GetDefaultPrice(source.ContentLink);

            var product = new TProduct
            {
                Id        = source.ContentLink.ID,
                Name      = source.DisplayName,
                UrlKey    = source.RouteSegment,
                UrlPath   = source.SeoUri,
                IsInStock = new VsfStock {
                    IsInStock = true, Quantity = (int)variantQuantity
                },
                Sku             = source.Code,
                TaxClassId      = null,
                MediaGallery    = GetGallery(source),
                Image           = imageUrl ?? "",
                Thumbnail       = thumbnail,
                FinalPrice      = productPrice,
                Price           = productPrice,
                TypeId          = "configurable",
                SpecialPrice    = null,
                NewsFromDate    = null,
                NewsToDate      = null,
                SpecialFromDate = null,
                SpecialToDate   = null,
                CategoryIds     = source.GetCategories().Select(x => x.ID.ToString()),
                Category        = source.GetCategories().Select(x =>
                                                                new CategoryListItem {
                    Id = x.ID, Name = ContentLoaderWrapper.Get <NodeContent>(x).DisplayName
                }),
                Status              = 1,
                Visibility          = source.Status.Equals(VersionStatus.Published) ? 4 : 0,
                Weight              = 1,
                HasOptions          = configurableOptions.Count > 1 ? "1" : "0",
                RequiredOptions     = "0",
                ConfigurableOptions = configurableOptions,
                UpdatedAt           = source.Changed,
                CreatedAt           = source.Created
            };

            product.ConfigurableChildren = productVariations
                                           .Select(v => MapVariant(product, ContentLoaderWrapper.Get <VariationContent>(v))).ToList();
            return(product);
        }
Exemple #2
0
        private void UpdateCartLine(ILineItem updatedItem)
        {
            var variationLinkt = _referenceConverter.GetContentLink(updatedItem.Code);
            var variation      = _contentLoaderWrapper.Get <VariationContent>(variationLinkt);

            if (variation != null)
            {
                updatedItem.DisplayName = variation.DisplayName;
                updatedItem.PlacedPrice = _priceService.GetDefaultPrice(variation.PriceReference);
            }
        }
        public VsfSimpleProduct Map(VariationContent source)
        {
            var imageUrl        = source.CommerceMediaCollection.FirstOrDefault()?.AssetLink.GetUrl();
            var thumbnail       = UrlHelper.GetAsThumbnailUrl(imageUrl);
            var variantQuantity = GetTotalInventoryByEntry(source.Code);

            var productPrice = _priceService.GetDefaultPrice(source.ContentLink);

            var product = new VsfSimpleProduct
            {
                Id        = source.ContentLink.ID,
                Name      = source.DisplayName,
                UrlKey    = source.RouteSegment,
                UrlPath   = source.SeoUri,
                IsInStock = new VsfStock {
                    IsInStock = true, Quantity = (int)variantQuantity
                },
                Sku             = source.Code,
                TaxClassId      = null,
                Image           = imageUrl ?? "",
                Thumbnail       = thumbnail,
                FinalPrice      = productPrice,
                Price           = productPrice,
                TypeId          = "simple",
                SpecialPrice    = null,
                NewsFromDate    = null,
                NewsToDate      = null,
                SpecialFromDate = null,
                SpecialToDate   = null,
                CategoryIds     = source.GetCategories().Select(x => x.ID.ToString()),
                Category        = source.GetCategories().Select(x =>
                                                                new CategoryListItem {
                    Id = x.ID, Name = _contentLoaderWrapper.Get <NodeContent>(x).DisplayName
                }),
                Status          = 1,
                Visibility      = 1, //hidden from vue store front list...
                Weight          = 1,
                HasOptions      = "0",
                RequiredOptions = "0",
                UpdatedAt       = source.Changed,
                CreatedAt       = source.Created
            };

            return(product);
        }
        public async Task <VsfStockCheck> Check(string code)
        {
            var variationLink = _referenceConverter.GetContentLink(code);
            var variation     = _contentLoaderWrapper.Get <VariationContent>(variationLink);
            var productLink   = variation.GetParentProducts().First();
//            var product = _contentLoader.Get<ProductContent>(productLink);
            var quantity = _inventoryService.QueryByEntry(new[] { code }).Sum(x => x.PurchaseAvailableQuantity);

            return(await Task.FromResult(
                       new VsfStockCheck
            {
                ItemId = variationLink.ID,
                ProductId = productLink.ID,
                StockId = 1,     //todo
                Qty = quantity,
                IsInStock = quantity > 0,
                IsQtyDecimal = false,
                ShowDefaultNotificationMessage = false,
                UseConfigMinQty = true,
                MinQty = variation.MinQuantity ?? 0,
                UseConfigMinSaleQty = true,
                MinSaleQty = 1,
                UseConfigMaxSaleQty = true,
                MaxSaleQty = variation.MaxQuantity ?? 10000,
                UseConfigBackorders = true,
                Backorders = 0,
                UseConfigNotifyStockQty = true,
                NotifyStockQty = 1,
                UseConfigQtyIncrements = true,
                QtyIncrements = 0,
                UseConfigEnableQtyInc = true,
                EnableQtyIncrements = false,
                UseConfigManageStock = true,
                ManageStock = true,
                LowStockDate = null,
                IsDecimalDivided = false,
                StockStatusChangedAuto = 0
            }));
        }
Exemple #5
0
        public void OnProductContent(NodeContent parent, ProductContent productContent)
        {
            _categoryTreeBuilder.AddProductCount(parent);

            var vsfProduct = _productMapper.Map(productContent);

            _indexingService.AddForIndexing(vsfProduct);

            var productVariations = productContent
                                    .GetVariants()
                                    .ToList();

            foreach (var variantContent in productVariations)
            {
                var variant          = _contentLoaderWrapper.Get <VariationContent>(variantContent);
                var vsfProductSimple = _simpleProductMapper.Map(variant);

                _indexingService.AddForIndexing(vsfProductSimple);
            }

            _contentPropertyLoader.ReadProperties(productContent);
        }
Exemple #6
0
 public T Get <T>(ContentReference reference) where T : IContentData
 {
     return(_contentLoaderWrapper.Get <T>(reference));
 }