public static IndexAction ElitUaApiModelToIndexAction( ElitPriceListRecord apiProduct, long updatedOnUtcTimestamp) { if (apiProduct == null) { return(null); } var source = EkProductSourceEnum.ElitUa; var productKey = new EkProductKey(source, ReplaceInvalidAzureSearchKeySymbolsWithDash(apiProduct.ActiveItemNo)) .ToKey(); var nameRu = GetValueOrFallback(apiProduct.EcatDescription, apiProduct.ItemDescription); var product = new Document() { ["key"] = productKey, ["updatedOnUtcTimestamp"] = updatedOnUtcTimestamp, ["source"] = (int)source, ["sourceId"] = apiProduct.ActiveItemNo, ["partNumber"] = apiProduct.PartNumber, ["cleanedPartNumber"] = PartNumberCleaner.GetCleanedPartNumber(apiProduct.PartNumber), ["brandName"] = apiProduct.Brand, ["cleanedBrandPartNumber"] = PartNumberCleaner.GetCleanedBrandPartNumber( brandName: apiProduct.Brand, partNumber: apiProduct.PartNumber), ["name_ru"] = SearchTextHelpers.TrimNameAndAddBrandIfMissed( productName: nameRu, brandName: apiProduct.Brand), ["price"] = (double)apiProduct.CustomerPrice, }; return(IndexAction.MergeOrUpload(product)); }
public static IndexAction OmegaAutoBizApiModelToIndexAction( ProductSearchRecord apiProduct, long updatedOnUtcTimestamp) { if (apiProduct == null) { return(null); } var source = EkProductSourceEnum.OmegaAutoBiz; var productKey = new EkProductKey(source, apiProduct.ProductId.ToString()) .ToKey(); var price = GetValueOrFallback(apiProduct.CustomerPrice, apiProduct.Price); if (price == 0) { return(IndexAction.Delete(new Document() { ["key"] = productKey, })); } var partNumber = apiProduct.Number?.Trim(); var brandName = apiProduct.BrandDescription?.Trim(); var nameRu = apiProduct.Description?.Trim(); var nameUk = GetValueOrFallback(apiProduct.DescriptionUkr?.Trim(), nameRu); var description = apiProduct.Info?.Trim(); var product = new Document() { ["key"] = productKey, ["updatedOnUtcTimestamp"] = updatedOnUtcTimestamp, ["source"] = (int)source, ["sourceId"] = apiProduct.ProductId.ToString(), ["partNumber"] = partNumber, ["cleanedPartNumber"] = PartNumberCleaner.GetCleanedPartNumber(partNumber), ["brandName"] = brandName, ["cleanedBrandPartNumber"] = PartNumberCleaner.GetCleanedBrandPartNumber( brandName: brandName, partNumber: partNumber), ["name_ru"] = SearchTextHelpers.TrimNameAndAddBrandIfMissed( productName: nameRu, brandName: brandName), ["name_uk"] = SearchTextHelpers.TrimNameAndAddBrandIfMissed( productName: nameUk, brandName: brandName), ["description_ru"] = description, ["description_uk"] = description, ["price"] = (double)price, }; return(IndexAction.MergeOrUpload(product)); }
public static EkProduct EkAllegroPlOfferToProduct(Offer offer, decimal exchangeRate) { Assure.ArgumentNotNull(offer, nameof(offer)); var productKey = new EkProductKey(EkProductSourceEnum.AllegroPl, offer.Id); EkProductStateEnum state; switch (offer.State) { case OfferStateEnum.Used: state = EkProductStateEnum.Used; break; case OfferStateEnum.Recovered: state = EkProductStateEnum.Recovered; break; case OfferStateEnum.Broken: state = EkProductStateEnum.Broken; break; default: case OfferStateEnum.New: state = EkProductStateEnum.New; break; } decimal deliveryPrice; if (offer.DeliveryOptions?.Length > 0) { deliveryPrice = offer.DeliveryOptions .Max(x => x.Price); } else { deliveryPrice = 0; } var product = new EkProduct() { Key = productKey.ToKey(), PartNumber = null, BrandName = null, Source = EkProductSourceEnum.AllegroPl, SourceId = offer.Id, CategoryId = offer.CategoryId, Name = offer.Name, Description = offer.Description, SpecificationsJson = new MultiLanguageString(), Photos = offer.Images? .Select(x => new EkProductPhoto() { Url = x.Url }) .ToArray(), BasePrice = offer.Price, BasePriceCurrencyCode = offer.PriceCurrencyCode, DeliveryPrice = deliveryPrice, State = state, ProductionYear = null, }; var isSpecialEngineTransmissionProduct = IsSpecialEngineTransmissionProduct(product); if (isSpecialEngineTransmissionProduct && product.State == EkProductStateEnum.Broken) { product.Price = 0; product.PriceCurrencyCode = "UAH"; product.PriceCalculationInfo = "Forbidden (broken Engine/Transmission)"; } else { var P_Price = product.BasePrice; var D_Price = product.DeliveryPrice; var M_Markup = GetC_Markup(product, isSpecialEngineTransmissionProduct); var T_Taxes = GetB_Taxes(product, isSpecialEngineTransmissionProduct); var R_Rate = exchangeRate; var price = (P_Price + D_Price) * (1 + T_Taxes) * (1 + M_Markup) * R_Rate; product.Price = RoundPrice(price); product.PriceCurrencyCode = "UAH"; product.PriceCalculationInfo = $"Formula=((P+D)+M%+T%)*R, P={P_Price}, D={D_Price}, M={M_Markup:P}, T={T_Taxes:P}, R={R_Rate}, Category={(isSpecialEngineTransmissionProduct ? "Engine/Transmission" : "Regular")}"; } return(product); }