public virtual IEnumerable <T> GetSiblingVariants <T>(string code) where T : VariationContent { var productRelations = _relationRepository.GetParents <ProductVariation>(_referenceConverter.GetContentLink(code)); var siblingsRelations = _relationRepository.GetChildren <ProductVariation>(productRelations.First().Parent); return(GetVariants <T>(siblingsRelations.Select(x => x.Child), _languageResolver.GetPreferredCulture())); }
public Task <VariantsResponce> Handle(VariantsRequest request, CancellationToken cancellationToken) { var variationReferences = _relationRepository.GetChildren <ProductVariation>(request.ProductReference); var variations = _contentLoader.GetItems(variationReferences.Select(x => x.Child), new LoaderOptions { LanguageLoaderOption.FallbackWithMaster() }).OfType <MovieVariant>(); var prices = _customerPriceService.GetPrices(variations.Select(x => x.Code)).ToDictionary(x => x.CatalogKey.CatalogEntryCode, y => y); var discount = _customerPriceService.GetDiscountPrices(variations.Select(x => x.ContentLink)).ToDictionary(x => x.EntryLink, y => y.DiscountPrices); var result = variations.Select(x => new Variant() { Code = x.Code, Name = x.Name, Primary = x.IsPrimary, DisplayName = x.MediaTypes, NormalPrice = prices.GetPrice(x.Code), Discounts = discount.GetDiscounts(x.ContentLink) }).ToList(); var responce = new VariantsResponce() { Variants = result }; if (string.IsNullOrEmpty(request.CurrentVariantCode)) { responce.ActiveVariant = result.Where(x => x.Primary).FirstOrDefault(); } else { responce.ActiveVariant = result.Where(x => x.Code == request.CurrentVariantCode).FirstOrDefault(); } return(Task.FromResult(responce)); }
/// <summary> /// Gets all children for an entry, whether it's product-variation, bundle-variation/product, package-variation/product relation. /// </summary> /// <param name="entry">The catalog entry to retrieve children for</param> /// <returns></returns> public IEnumerable <EntryContentBase> GetChildren(EntryContentBase entry) { IEnumerable <EntryRelation> relations = _relationRepository.GetChildren <EntryRelation>(entry.ContentLink); IEnumerable <EntryContentBase> variations = relations.Select(x => _contentLoader.Get <EntryContentBase>(x.Child)); return(variations.Where(x => x != null)); }
public void EntryDeleted(CatalogContentUpdateEventArgs e) { Logger.Debug("EntryDeleted raised."); IEnumerable <ContentReference> contentLinks = GetContentLinks(e); // Variants IEnumerable <ContentReference> variantLinks = GetVariantReferences(contentLinks); VariationContent[] variants = _contentLoader.GetItems(variantLinks, CultureInfo.InvariantCulture) .OfType <VariationContent>() .ToArray(); foreach (VariationContent variant in variants) { foreach (var parent in variant.GetParentProducts()) { var product = _contentLoader.Get <ProductContent>(parent); IEnumerable <ContentReference> variantRefs = _relationRepository .GetChildren <ProductVariation>(product.ContentLink) .Select(r => r.Child); ICollection <VariationContent> productVariants = _contentLoader .GetItems(variantRefs, LanguageSelector.MasterLanguage()) .OfType <VariationContent>() .ToArray(); var configuration = KachingConfiguration.Instance; if (productVariants.Count == 1 && configuration.ExportSingleVariantAsProduct) { _productExportService.DeleteSingleVariantProduct(variant); } else { // Since variants are not independent datatypes in Ka-ching // a variant change is always a product update and not a delete _productExportService.ExportProduct(product, variant.Code); } } } // Products IEnumerable <ContentReference> productLinks = GetProductReferences(contentLinks); ProductContent[] products = _contentLoader.GetItems(productLinks, CultureInfo.InvariantCulture) .OfType <ProductContent>() .ToArray(); _productExportService.DeleteProducts(products); _productExportService.DeleteProductAssets(products); _productExportService.DeleteProductRecommendations(products); }
public string GetSiblingVariantCodeBySize(string siblingCode, string size) { ContentReference variationReference = _referenceConverter.GetContentLink(siblingCode); IEnumerable <ProductVariation> productRelations = _relationRepository.GetParents <ProductVariation>(variationReference).ToList(); IEnumerable <ProductVariation> siblingsRelations = _relationRepository.GetChildren <ProductVariation>(productRelations.First().Parent); IEnumerable <ContentReference> siblingsReferences = siblingsRelations.Select(x => x.Child); IEnumerable <IContent> siblingVariations = _contentLoader.GetItems(siblingsReferences, _preferredCulture).ToList(); var siblingVariant = siblingVariations.OfType <BaseVariant>().First(x => x.Code == siblingCode); foreach (var variant in siblingVariations.OfType <BaseVariant>()) { if (variant.Size.Equals(size, StringComparison.OrdinalIgnoreCase) && variant.Code != siblingCode && variant.Color.Equals(siblingVariant.Color, StringComparison.OrdinalIgnoreCase)) { return(variant.Code); } } return(null); }
public virtual IEnumerable <ContentIndexingResult> IndexVariations(ContentReference contentLink) { var contentReferencesToIndex = new List <ContentReference>() { contentLink }; contentReferencesToIndex.AddRange(RelationRepository.GetChildren <ProductVariation>(contentLink).Select(x => x.Child)); var contentsToIndex = ContentLoader.GetItems(contentReferencesToIndex, CultureInfo.InvariantCulture).ToList(); return(ContentIndexer.Index(contentsToIndex)); }
public void DeleteRelation(string sourceCode, string targetCode) { _logger.Debug($"Deleting relation between {sourceCode} and {targetCode}."); ContentReference sourceReference = _referenceConverter.GetContentLink(sourceCode); ContentReference targetReference = _referenceConverter.GetContentLink(targetCode); IEnumerable <Relation> entryRelations = _relationRepository.GetChildren <Relation>(sourceReference); Relation relation = entryRelations.FirstOrDefault(x => x.Child.Equals(targetReference)); if (relation != null) { _relationRepository.RemoveRelation(relation); } }
public AddToCartResult AddToCart(ICart cart, string code, decimal quantity) { var result = new AddToCartResult(); var contentLink = _referenceConverter.GetContentLink(code); var entryContent = _contentLoader.Get <EntryContentBase>(contentLink); if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(contentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry.Code, relation.Quantity ?? 1); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } var lineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == code && !x.IsGift); if (lineItem == null) { lineItem = cart.CreateLineItem(code, _orderGroupFactory); lineItem.DisplayName = entryContent.DisplayName; lineItem.Quantity = quantity; cart.AddLineItem(lineItem, _orderGroupFactory); } else { var shipment = cart.GetFirstShipment(); cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } var validationIssues = ValidateCart(cart); AddValidationMessagesToResult(result, lineItem, validationIssues); return(result); }
public string GetSiblingVariantCodeBySize(string siblingCode, string size) { var variationReference = _referenceConverter.GetContentLink(siblingCode); var productRelations = _relationRepository.GetParents <ProductVariation>(variationReference).ToList(); var siblingsRelations = _relationRepository.GetChildren <ProductVariation>(productRelations.First().Parent); var siblingsReferences = siblingsRelations.Select(x => x.Child); var siblingVariants = GetAvailableVariants(siblingsReferences).OfType <GenericVariant>().ToList(); var siblingVariant = siblingVariants.First(x => x.Code == siblingCode); foreach (var variant in siblingVariants) { if (variant.Size.Equals(size, StringComparison.OrdinalIgnoreCase) && variant.Code != siblingCode && variant.Color.Equals(siblingVariant.Color, StringComparison.OrdinalIgnoreCase)) { return(variant.Code); } } return(null); }
public AddToCartResult AddToCart(ICart cart, EntryContentBase entryContent, decimal quantity, string deliveryMethod, string warehouseCode, List <string> dynamicVariantOptionCodes) { var result = new AddToCartResult(); var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); if (contact?.OwnerId != null) { var org = cart.GetString("OwnerOrg"); if (string.IsNullOrEmpty(org)) { cart.Properties["OwnerOrg"] = contact.OwnerId.Value.ToString().ToLower(); } } IWarehouse warehouse = null; if (deliveryMethod.Equals("instore") && !string.IsNullOrEmpty(warehouseCode)) { warehouse = _warehouseRepository.Get(warehouseCode); } if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(entryContent.ContentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry, (relation.Quantity ?? 1) * quantity, deliveryMethod, warehouseCode, dynamicVariantOptionCodes); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } var form = cart.GetFirstForm(); if (form == null) { form = _orderGroupFactory.CreateOrderForm(cart); form.Name = cart.Name; cart.Forms.Add(form); } var shipment = cart.GetFirstForm().Shipments.FirstOrDefault(x => string.IsNullOrEmpty(warehouseCode) || (x.WarehouseCode == warehouseCode && x.ShippingMethodId == InStorePickupInfoModel.MethodId)); if (warehouse != null) { if (shipment != null && !shipment.LineItems.Any()) { shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } else { shipment = form.Shipments.FirstOrDefault(x => !string.IsNullOrEmpty(x.WarehouseCode) && x.WarehouseCode.Equals(warehouse.Code)); if (shipment == null) { if (cart.GetFirstShipment().LineItems.Count > 0) { shipment = _orderGroupFactory.CreateShipment(cart); } else { shipment = cart.GetFirstShipment(); } shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); if (cart.GetFirstShipment().LineItems.Count > 0) { cart.GetFirstForm().Shipments.Add(shipment); } } } } if (shipment == null) { var cartFirstShipment = cart.GetFirstShipment(); if (cartFirstShipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } else { if (cartFirstShipment.LineItems.Count > 0) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } else { shipment = cartFirstShipment; } } } var lineItem = shipment.LineItems.FirstOrDefault(x => x.Code == entryContent.Code); decimal originalLineItemQuantity = 0; if (lineItem == null) { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); var lineDisplayName = entryContent.DisplayName; if (dynamicVariantOptionCodes?.Count > 0) { lineItem.Properties[VariantOptionCodesProperty] = string.Join(",", dynamicVariantOptionCodes.OrderBy(x => x)); lineDisplayName += " - " + lineItem.Properties[VariantOptionCodesProperty]; } lineItem.DisplayName = lineDisplayName; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } else { if (lineItem.Properties[VariantOptionCodesProperty] != null) { var variantOptionCodesLineItem = lineItem.Properties[VariantOptionCodesProperty].ToString().Split(','); var intersectCodes = variantOptionCodesLineItem.Intersect(dynamicVariantOptionCodes); if (intersectCodes != null && intersectCodes.Any() && intersectCodes.Count() == variantOptionCodesLineItem.Length && intersectCodes.Count() == dynamicVariantOptionCodes.Count) { originalLineItemQuantity = lineItem.Quantity; cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } else { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); lineItem.Properties[VariantOptionCodesProperty] = string.Join(",", dynamicVariantOptionCodes.OrderBy(x => x)); lineItem.DisplayName = entryContent.DisplayName + " - " + lineItem.Properties[VariantOptionCodesProperty]; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } } else { originalLineItemQuantity = lineItem.Quantity; cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } var validationIssues = ValidateCart(cart); var newLineItem = shipment.LineItems.FirstOrDefault(x => x.Code == entryContent.Code); var isAdded = (newLineItem != null ? newLineItem.Quantity : 0) - originalLineItemQuantity > 0; AddValidationMessagesToResult(result, lineItem, validationIssues, isAdded); return(result); }
#pragma warning restore 649 /// <summary> /// Gets all variants/SKUs for a product /// </summary> /// <param name="productContent">The product</param> /// <param name="relationRepository">The relation repository</param> /// <returns>Collection of variation references</returns> public static IEnumerable <ContentReference> GetVariations(this ProductContent productContent, IRelationRepository relationRepository) { return(relationRepository.GetChildren <ProductVariation>(productContent.ContentLink).Select(r => r.Child)); }
public AddToCartResult AddToCart(ICart cart, EntryContentBase entryContent, decimal quantity, string deliveryMethod, string warehouseCode) { var result = new AddToCartResult(); var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); if (contact?.OwnerId != null) { var org = cart.GetString("OwnerOrg"); if (string.IsNullOrEmpty(org)) { cart.Properties["OwnerOrg"] = contact.OwnerId.Value.ToString().ToLower(); } } IWarehouse warehouse = null; if (deliveryMethod.Equals("instore") && !string.IsNullOrEmpty(warehouseCode)) { warehouse = _warehouseRepository.Get(warehouseCode); } if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(entryContent.ContentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry, relation.Quantity ?? 1, deliveryMethod, warehouseCode); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } var form = cart.GetFirstForm(); if (form == null) { form = _orderGroupFactory.CreateOrderForm(cart); form.Name = cart.Name; cart.Forms.Add(form); } var shipment = cart.GetFirstShipment(); if (warehouse != null) { if (shipment != null && !shipment.LineItems.Any()) { shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } else { shipment = form.Shipments.FirstOrDefault(x => !string.IsNullOrEmpty(x.WarehouseCode) && x.WarehouseCode.Equals(warehouse.Code)); if (shipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; cart.GetFirstForm().Shipments.Add(shipment); shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } } } if (shipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } var lineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == entryContent.Code); if (lineItem == null) { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); lineItem.DisplayName = entryContent.DisplayName; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } else { cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } var validationIssues = ValidateCart(cart); AddValidationMessagesToResult(result, lineItem, validationIssues); return(result); }
#pragma warning restore 649 /// <summary> /// Gets all bundle entries for a bundle /// </summary> /// <param name="bundleContent">The bundle content to use</param> /// <param name="relationRepository">The relation repository</param> /// <returns>Collection of bundle entry references</returns> public static IEnumerable <ContentReference> GetBundleEntries(this BundleContent bundleContent, IRelationRepository relationRepository) { return(relationRepository.GetChildren <BundleEntry>(bundleContent.ContentLink).Select(r => r.Child)); }
public Product BuildKaChingProduct( ProductContent product, ICollection <string> tags, KachingConfiguration configuration, string skipVariantCode) { var kachingProduct = new Product(); kachingProduct.Id = product.Code.SanitizeKey(); kachingProduct.Barcode = GetPropertyStringValue(product, configuration.SystemMappings.BarcodeMetaField); kachingProduct.Name = _l10nStringFactory.GetLocalizedString(product, nameof(product.DisplayName)); kachingProduct.Description = _l10nStringFactory.GetLocalizedString(product, configuration.SystemMappings.DescriptionMetaField); foreach (var mapping in configuration.AttributeMappings.Cast <AttributeMappingElement>()) { object value = GetAttributeValue(product, mapping.MetaField); if (value == null) { continue; } kachingProduct.Attributes[mapping.AttributeId] = value; } /* ---------------------------- */ /* Example of dimension and dimension value construction from the Quicksilver site. */ /* ---------------------------- */ //var dimensions = new List<Dimension>(); //var sizeDimension = new Dimension(); //sizeDimension.Id = "Size"; //sizeDimension.Name = new L10nString("Size"); //sizeDimension.Values = new List<DimensionValue>(); //foreach (var size in product.AvailableSizes) //{ // var sizeValue = new DimensionValue(); // sizeValue.Id = size.ToLower().Replace(' ', '_'); // sizeValue.Name = new L10nString(size); // sizeDimension.Values.Add(sizeValue); //} //dimensions.Add(sizeDimension); //var colorDimension = new Dimension(); //colorDimension.Id = "Color"; //colorDimension.Name = new L10nString("Color"); //colorDimension.Values = new List<DimensionValue>(); //foreach (var color in product.AvailableColors) //{ // var colorValue = new DimensionValue(); // colorValue.Id = color.ToLower().Replace(' ', '_'); // colorValue.Name = new L10nString(color); // colorDimension.Values.Add(colorValue); //} //dimensions.Add(colorDimension); //kachingProduct.Dimensions = dimensions; CommerceMedia productImage = product.CommerceMediaCollection.FirstOrDefault(); if (productImage != null) { Uri absoluteUrl = GetAbsoluteUrl(productImage.AssetLink); kachingProduct.ImageUrl = absoluteUrl?.AbsoluteUri; } IEnumerable <ContentReference> variantRefs = _relationRepository .GetChildren <ProductVariation>(product.ContentLink) .Select(r => r.Child); ICollection <VariationContent> variants = _contentLoader .GetItems(variantRefs, LanguageSelector.MasterLanguage()) .OfType <VariationContent>() .ToArray(); if (variants.Count == 1 && configuration.ExportSingleVariantAsProduct) { // If the product has only one variant and ExportSingleVariantAsProduct is configured to true, // then put all variant properties on the product instead. var variant = variants.First(); kachingProduct.Id = variant.Code.SanitizeKey(); kachingProduct.Barcode = GetPropertyStringValue(variant, configuration.SystemMappings.BarcodeMetaField); kachingProduct.Name = _l10nStringFactory.GetLocalizedString(variant, nameof(variant.DisplayName)); MarketPrice retailPrice = MarketPriceForCode(variant.Code); AddProductPricing(kachingProduct, product, retailPrice, configuration.SystemMappings.PriceUnitMetaField); foreach (var mapping in configuration.AttributeMappings.Cast <AttributeMappingElement>()) { object value = GetAttributeValue(variant, mapping.MetaField); if (value == null) { continue; } kachingProduct.Attributes[mapping.AttributeId] = value; } if (kachingProduct.ImageUrl == null) { CommerceMedia variantImage = variant.CommerceMediaCollection.FirstOrDefault(); if (variantImage != null) { Uri absoluteUrl = GetAbsoluteUrl(variantImage.AssetLink); kachingProduct.ImageUrl = absoluteUrl?.AbsoluteUri; } } } else if (variants.Count > 0) { var kachingVariants = new List <Variant>(variants.Count); foreach (var variant in variants) { if (skipVariantCode != null && skipVariantCode == variant.Code) { continue; } var kachingVariant = new Variant(); kachingVariant.Id = variant.Code.SanitizeKey(); kachingVariant.Barcode = GetPropertyStringValue(variant, configuration.SystemMappings.BarcodeMetaField); var variantName = _l10nStringFactory.GetLocalizedString(variant, nameof(variant.DisplayName)); if (!variantName.Equals(kachingProduct.Name)) { kachingVariant.Name = variantName; } if (kachingProduct.UnitPricing == null) { kachingVariant.RetailPrice = MarketPriceForCode(variant.Code); } foreach (var mapping in configuration.AttributeMappings.Cast <AttributeMappingElement>()) { object value = GetAttributeValue(variant, mapping.MetaField); if (value == null) { continue; } kachingVariant.Attributes[mapping.AttributeId] = value; } CommerceMedia variantImage = variant.CommerceMediaCollection.FirstOrDefault(); if (variantImage != null) { Uri absoluteUrl = GetAbsoluteUrl(variantImage.AssetLink); kachingVariant.ImageUrl = absoluteUrl?.AbsoluteUri; } if (kachingProduct.ImageUrl == null) { kachingProduct.ImageUrl = kachingVariant.ImageUrl; } kachingVariants.Add(kachingVariant); } kachingProduct.Variants = kachingVariants; } /* ---------------------------- */ /* Assign tags to enable category navigation */ /* ---------------------------- */ kachingProduct.Tags = new Dictionary <string, bool>(); foreach (var tag in tags) { kachingProduct.Tags[tag] = true; } return(kachingProduct); }
private IEnumerable <EntryRelation> GetEntriesRelation(EntryContentBase content) => _relationRepository.GetChildren <EntryRelation>(content.ContentLink);
public AddToCartResult AddToCart(ICart cart, string code, string warehouseCode, decimal quantity) { var result = new AddToCartResult(); var contentLink = _referenceConverter.GetContentLink(code); var entryContent = _contentLoader.Get <EntryContentBase>(contentLink); if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(contentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry.Code, warehouseCode, relation.Quantity ?? 1); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } ILineItem lineItem = null; if (!string.IsNullOrEmpty(warehouseCode)) { IShipment shipment = null; if (cart.GetFirstForm().Shipments.Count == 1 && string.IsNullOrEmpty(cart.GetFirstForm().Shipments.First().WarehouseCode)) { shipment = cart.GetFirstForm().Shipments.First(); shipment.WarehouseCode = warehouseCode; } else { shipment = cart.GetFirstForm().Shipments.FirstOrDefault(s => s.WarehouseCode.Equals(warehouseCode, StringComparison.CurrentCultureIgnoreCase)); } if (shipment == null) { shipment = cart.CreateShipment(_orderGroupFactory); shipment.WarehouseCode = warehouseCode; cart.AddShipment(shipment); } lineItem = shipment.LineItems.FirstOrDefault(x => x.Code == code && !x.IsGift); if (lineItem == null) { //this is just like AddNewLineItem but doesn't add there - adds to shipment instead lineItem = cart.CreateLineItem(code, _orderGroupFactory); lineItem.Quantity = quantity; lineItem.DisplayName = entryContent.DisplayName; //cart.AddLineItem(newLineItem, _orderGroupFactory); var price = _pricingService.GetPrice(code); if (price != null) { lineItem.PlacedPrice = price.UnitPrice.Amount; } cart.AddLineItem(shipment, lineItem); } else { cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } else { lineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == code && !x.IsGift); if (lineItem == null) { lineItem = AddNewLineItem(cart, code, quantity, entryContent.DisplayName); } else { var shipment = cart.GetFirstShipment(); cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } var validationIssues = ValidateCart(cart); AddValidationMessagesToResult(result, lineItem, validationIssues); return(result); }
#pragma warning restore 649 /// <summary> /// Gets package entries for a package /// </summary> /// <param name="packageContent">The package content</param> /// <param name="relationRepository">The relation repository</param> /// <returns>Collection of package entry references</returns> public static IEnumerable <ContentReference> GetPackageEntries(this PackageContent packageContent, IRelationRepository relationRepository) { return(relationRepository.GetChildren <PackageEntry>(packageContent.ContentLink).Select(r => r.Child)); }