| | | 1 | | using Newtonsoft.Json.Linq; |
| | | 2 | | |
| | | 3 | | namespace Services.BitrixStockServices; |
| | | 4 | | |
| | | 5 | | /// <summary>Собирает JObject цены Ozon из строки ozon_products для PriceOptimizationManager.</summary> |
| | | 6 | | public static class OzonProductCatalogPriceJsonBuilder |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Формат совместим с Ozon <c>/v5/product/info/prices</c> (commissions — объект, не массив). |
| | | 10 | | /// </summary> |
| | | 11 | | public static JObject Build(OzonProductCatalogRow row) |
| | | 12 | | { |
| | 3 | 13 | | var priceObj = new JObject |
| | 3 | 14 | | { |
| | 3 | 15 | | ["price"] = row.Price, |
| | 3 | 16 | | ["old_price"] = row.OldPrice, |
| | 3 | 17 | | ["marketing_price"] = row.MarketingPrice, |
| | 3 | 18 | | ["min_price"] = row.MinOzonPrice, |
| | 3 | 19 | | ["marketing_seller_price"] = row.MarketingPrice ?? row.Price, |
| | 3 | 20 | | ["vat"] = "0" |
| | 3 | 21 | | }; |
| | | 22 | | |
| | 3 | 23 | | var commissions = new JObject(); |
| | 3 | 24 | | if (row.CommFbs.HasValue) |
| | 2 | 25 | | commissions["sales_percent_fbs"] = row.CommFbs.Value; |
| | 3 | 26 | | if (row.CommFbo.HasValue) |
| | 1 | 27 | | commissions["sales_percent_fbo"] = row.CommFbo.Value; |
| | 3 | 28 | | if (row.FbsMileMin.HasValue) |
| | 0 | 29 | | commissions["fbs_first_mile_min_amount"] = row.FbsMileMin.Value; |
| | 3 | 30 | | if (row.FbsMileMax.HasValue) |
| | 2 | 31 | | commissions["fbs_first_mile_max_amount"] = row.FbsMileMax.Value; |
| | 3 | 32 | | if (row.FbsDirectMin.HasValue) |
| | 0 | 33 | | commissions["fbs_direct_flow_trans_min_amount"] = row.FbsDirectMin.Value; |
| | 3 | 34 | | if (row.FbsDirectMax.HasValue) |
| | 2 | 35 | | commissions["fbs_direct_flow_trans_max_amount"] = row.FbsDirectMax.Value; |
| | 3 | 36 | | if (row.FbsDeliv.HasValue) |
| | 2 | 37 | | commissions["fbs_deliv_to_customer_amount"] = row.FbsDeliv.Value; |
| | | 38 | | |
| | 3 | 39 | | var item = new JObject |
| | 3 | 40 | | { |
| | 3 | 41 | | ["offer_id"] = row.OfferId, |
| | 3 | 42 | | ["product_id"] = row.ProductId, |
| | 3 | 43 | | ["price"] = priceObj, |
| | 3 | 44 | | ["commissions"] = commissions |
| | 3 | 45 | | }; |
| | | 46 | | |
| | 3 | 47 | | if (row.Acquiring.HasValue) |
| | 2 | 48 | | item["acquiring"] = row.Acquiring.Value; |
| | | 49 | | |
| | 3 | 50 | | if (row.MinOzonPrice.HasValue) |
| | | 51 | | { |
| | 1 | 52 | | item["price_indexes"] = new JObject |
| | 1 | 53 | | { |
| | 1 | 54 | | ["ozon_index_data"] = new JObject |
| | 1 | 55 | | { |
| | 1 | 56 | | ["min_price"] = row.MinOzonPrice.Value |
| | 1 | 57 | | } |
| | 1 | 58 | | }; |
| | | 59 | | } |
| | | 60 | | |
| | 3 | 61 | | return item; |
| | | 62 | | } |
| | | 63 | | } |