public Product(EkProduct ekProduct) { Assure.ArgumentNotNull(ekProduct, nameof(ekProduct)); EkProduct = ekProduct; Key = ekProduct.Key; ThumbnailUrl = ekProduct.GetThumbnailUrl(); Photos = ekProduct.Photos; Name = ekProduct.Name?.GetValue(Languages.RussianCode); Price = ekProduct.Price; PriceString = Price.ToAmountStringWithSpaces(); PriceComment = ekProduct.Source == EkProductSourceEnum.AllegroPl ? "с учетом доставки\nдоставка 1-7 дней" : "доставка 1-3 дня"; SetStateString(ekProduct.State); ProductionYear = ekProduct.ProductionYear; PartNumber = ekProduct.PartNumber; IsNotAvailable = Price <= 0; // description _descriptionValue = ekProduct.Description; UpdateParametersByValue(); IsDescriptionRequestRequired = !IsNotAvailable && _descriptionValue == null && ekProduct.Source == EkProductSourceEnum.AllegroPl; }
public static EkTransactionProduct FromProduct(EkProduct product, MultiLanguageString description, int quantity) { Assure.ArgumentNotNull(product, nameof(product)); return(new EkTransactionProduct() { Key = product.Key, Source = product.Source, SourceId = product.SourceId, BrandName = product.BrandName, PartNumber = product.PartNumber, CategoryId = product.CategoryId, Name = product.Name, Description = description, ThumbnailUrl = product.GetThumbnailUrl(), BasePrice = product.BasePrice, BasePriceCurrencyCode = product.BasePriceCurrencyCode, DeliveryPrice = product.DeliveryPrice, Price = product.Price, PriceCurrencyCode = product.PriceCurrencyCode, PriceCalculationInfo = product.PriceCalculationInfo, State = product.State, Quantity = quantity, }); }
public Product(EkProduct ekProduct) { Assure.ArgumentNotNull(ekProduct, nameof(ekProduct)); EkProduct = ekProduct; Key = ekProduct.Key; ThumbnailUrl = ekProduct.GetThumbnailUrl(); Photos = ekProduct.Photos; Name = ekProduct.Name?.GetValue(Languages.RussianCode); Price = ekProduct.Price; PriceString = Price.ToAmountStringWithSpaces(); PriceComment = ekProduct.Source == EkProductSourceEnum.AllegroPl ? "с учетом доставки\nдоставка 1-7 дней" : "доставка 1-3 дня"; switch (ekProduct.State) { case EkProductStateEnum.New: StateString = "новое"; break; case EkProductStateEnum.Used: StateString = "б/у"; break; case EkProductStateEnum.Recovered: StateString = "восстановлено"; break; case EkProductStateEnum.Broken: StateString = "неисправно"; break; default: StateString = "?"; break; } ProductionYear = ekProduct.ProductionYear; PartNumber = ekProduct.PartNumber; IsNotAvailable = Price <= 0; // description _descriptionValue = ekProduct.Description; UpdateDescriptionByValue(); IsDescriptionRequestRequired = !IsNotAvailable && _descriptionValue == null && ekProduct.Source == EkProductSourceEnum.AllegroPl; }
private static decimal GetB_Taxes(EkProduct product, bool isSpecialEngineTransmissionProduct) { int percentage; if (isSpecialEngineTransmissionProduct) { percentage = 15; } else { percentage = 0; } return(((decimal)percentage) / 100); }
public static EkProduct EkOmegaPartNumberBrandToProduct(EkPartNumberBrand partNumberBrand) { var product = new EkProduct() { Key = partNumberBrand.ProductKey, PartNumber = partNumberBrand.PartNumber, BrandName = partNumberBrand.BrandName, Source = EkProductSourceEnum.OmegaAutoBiz, Name = partNumberBrand.Name ?? new MultiLanguageString(), Description = new MultiLanguageString(), SpecificationsJson = new MultiLanguageString(), Photos = null, BasePrice = 0, BasePriceCurrencyCode = "UAH", DeliveryPrice = 0, State = EkProductStateEnum.New, ProductionYear = null, }; product.Price = RoundPrice(product.BasePrice); product.PriceCurrencyCode = product.BasePriceCurrencyCode; return(product); }
public override async Task <EkKioskProductSearchInEuropeGetResponse> ExecuteAsync(EkKioskProductSearchInEuropeGetRequest request) { //var kioskId = _currentUser.Id; //if (kioskId == 75) //{ // return await MySpecialLogicAsync(); //} var categoryId = request.CategoryId; if (string.IsNullOrEmpty(categoryId)) { categoryId = AutomotiveCategoryId; } OfferStateEnum offerState; switch (request.State) { case EkProductStateEnum.New: offerState = OfferStateEnum.New; break; case EkProductStateEnum.Used: offerState = OfferStateEnum.Used; break; case EkProductStateEnum.Recovered: offerState = OfferStateEnum.Recovered; break; case EkProductStateEnum.Broken: offerState = OfferStateEnum.Broken; break; default: offerState = OfferStateEnum.All; break; } OfferSortingEnum offerSorting; switch (request.Sorting) { case EkProductSearchSortingEnum.PriceAscending: offerSorting = OfferSortingEnum.PriceAsc; break; case EkProductSearchSortingEnum.PriceDescending: offerSorting = OfferSortingEnum.PriceDesc; break; default: case EkProductSearchSortingEnum.Default: offerSorting = OfferSortingEnum.Relevance; break; } // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; var searchOffersResponse = await _allegroPlClient.SearchOffersAsync( request.Term, request.TranslatedTerm, categoryId, offerState, offerSorting, request.From, request.Count, cancellationToken); try { await _allegroPlClient.ApplyTranslations(_translateService, searchOffersResponse.Offers, request.Term, request.TranslatedTerm, cancellationToken); } catch { } EkProduct[] products; if (searchOffersResponse.Offers?.Length > 0) { var exchangeRate = 6;//await GetExchangeRateAsync(); products = searchOffersResponse.Offers .Select(x => EkConvertHelper.EkAllegroPlOfferToProduct(x, exchangeRate)) .ToArray(); } else { products = new EkProduct[0]; } return(new EkKioskProductSearchInEuropeGetResponse() { Products = products, Total = searchOffersResponse.Total, TranslatedTerm = searchOffersResponse.TranslatedPhrase, }); }
public static EkProduct EkNewIndexProductToProduct(IndexProduct indexProduct) { Assure.ArgumentNotNull(indexProduct, nameof(indexProduct)); var photos = string.IsNullOrEmpty(indexProduct.ThumbnailUrl) ? null : new[] { new EkProductPhoto() { Url = indexProduct.ThumbnailUrl }, }; var product = new EkProduct() { Key = indexProduct.Key, PartNumber = indexProduct.PartNumber, BrandName = indexProduct.BrandName, Source = (EkProductSourceEnum)indexProduct.Source, SourceId = indexProduct.SourceId, Name = new MultiLanguageString() { [Languages.RussianCode] = indexProduct.Name_ru, }, Description = new MultiLanguageString() { [Languages.RussianCode] = indexProduct.Description_ru, }, SpecificationsJson = new MultiLanguageString() { [Languages.RussianCode] = indexProduct.SpecificationsJson_ru, }, Photos = photos, BasePrice = (decimal)(indexProduct.Price ?? 0), BasePriceCurrencyCode = "UAH", DeliveryPrice = 0, State = EkProductStateEnum.New, ProductionYear = indexProduct.ProductionYear, }; switch (product.Source) { case EkProductSourceEnum.OmegaAutoBiz: case EkProductSourceEnum.ElitUa: { var A_Price = product.BasePrice; // fixed markup const decimal C_Markup = 0.17m; // 17% var price = A_Price * (1 + C_Markup); product.Price = RoundPrice(price); product.PriceCalculationInfo = $"Formula=A+C%, A={A_Price}, C={C_Markup:P}, Source={product.Source}"; break; } default: { product.Price = 0; product.PriceCalculationInfo = $"Forbidden (source '{product.Source}' is not supported)"; break; } } product.PriceCurrencyCode = product.BasePriceCurrencyCode; return(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); }