Skip to content

Commit 23686f6

Browse files
committed
merge
2 parents eb60796 + b33b533 commit 23686f6

File tree

10 files changed

+217
-11
lines changed

10 files changed

+217
-11
lines changed

Source/FikaAmazonAPI.SampleCode/FeedsSample.cs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void AddOfferMessageMessage()
155155
GetFeedDetails(feedID);
156156
}
157157

158-
public void SubmitFeedPRICING(double PRICE, string SKU)
158+
public void SubmitFeedPRICING(decimal PRICE, string SKU)
159159
{
160160

161161
ConstructFeedService createDocument = new ConstructFeedService(amazonConnection.GetCurrentSellerID, "1.02");
@@ -167,7 +167,7 @@ public void SubmitFeedPRICING(double PRICE, string SKU)
167167
StandardPrice = new StandardPrice()
168168
{
169169
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
170-
Value = (PRICE).ToString("0.00")
170+
Value = decimal.Round(PRICE, 2)
171171
}
172172
});
173173
createDocument.AddPriceMessage(list);
@@ -180,6 +180,52 @@ public void SubmitFeedPRICING(double PRICE, string SKU)
180180

181181
}
182182

183+
public async Task SubmitFeedPRICING_JSONAsync(string SKU, decimal PRICE, decimal? minPrice = null, decimal? maxPrice = null)
184+
{
185+
ConstructJSONFeedService createDocument = new ConstructJSONFeedService(amazonConnection.GetCurrentSellerID);
186+
187+
var list = new List<PriceMessage>();
188+
var msg = new PriceMessage()
189+
{
190+
SKU = SKU,
191+
StandardPrice = new StandardPrice()
192+
{
193+
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
194+
Value = decimal.Round(PRICE, 2)
195+
}
196+
};
197+
198+
if (maxPrice != null)
199+
{
200+
msg.MaximumSellerAllowedPrice = new StandardPrice()
201+
{
202+
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
203+
Value = decimal.Round(maxPrice.Value, 2)
204+
};
205+
}
206+
207+
if (minPrice != null)
208+
{
209+
msg.MinimumSellerAllowedPrice = new StandardPrice()
210+
{
211+
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
212+
Value = decimal.Round(minPrice.Value, 2)
213+
};
214+
}
215+
216+
217+
list.Add(msg);
218+
createDocument.AddPriceMessage(list);
219+
220+
var jsonString = createDocument.GetJSON();
221+
222+
string feedID = await amazonConnection.Feed.SubmitFeedAsync(jsonString, FeedType.JSON_LISTINGS_FEED, null, null, ContentType.JSON);
223+
224+
225+
await GetJsonFeedDetails(feedID);
226+
227+
}
228+
183229
public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, decimal salePrice, DateTime startDate, DateTime endDate)
184230
{
185231
var currencyCode = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString();
@@ -193,14 +239,14 @@ public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, deci
193239
StandardPrice = new StandardPrice
194240
{
195241
currency = currencyCode,
196-
Value = price.ToString("0.00")
242+
Value = decimal.Round(price, 2)
197243
},
198244
Sale = new Sale
199245
{
200246
SalePrice = new StandardPrice
201247
{
202248
currency = currencyCode,
203-
Value = salePrice.ToString("0.00")
249+
Value = decimal.Round(salePrice, 2)
204250
},
205251
StartDate = startDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"),
206252
EndDate = endDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK")
@@ -260,7 +306,7 @@ public async Task SubmitJsonFeedPricing(string sku, decimal price)
260306
}
261307

262308

263-
public void SubmitFeedSale(double PRICE, string SKU)
309+
public void SubmitFeedSale(decimal PRICE, string SKU)
264310
{
265311

266312
ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02");
@@ -272,7 +318,7 @@ public void SubmitFeedSale(double PRICE, string SKU)
272318
StandardPrice = new StandardPrice()
273319
{
274320
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
275-
Value = (PRICE).ToString("0.00")
321+
Value = decimal.Round(PRICE, 2) //(PRICE).ToString("0.00")
276322
},
277323
Sale = new Sale()
278324
{
@@ -281,7 +327,7 @@ public void SubmitFeedSale(double PRICE, string SKU)
281327
SalePrice = new StandardPrice()
282328
{
283329
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
284-
Value = (PRICE - 10).ToString("0.00")
330+
Value = decimal.Round(PRICE, 2) - 10
285331
}
286332
}
287333
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using FikaAmazonAPI.ConstructFeed.JsonMessages;
2+
using FikaAmazonAPI.ConstructFeed.Messages;
3+
using Newtonsoft.Json;
4+
using System.Collections.Generic;
5+
6+
namespace FikaAmazonAPI.ConstructFeed
7+
{
8+
public class ConstructJSONFeedService
9+
{
10+
JsonMessagesData jsonMessagesData = new JsonMessagesData();
11+
public ConstructJSONFeedService(string sellerId, string version = "2.0", string issueLocale = "en_US")
12+
{
13+
jsonMessagesData.header = new HeaderData()
14+
{
15+
issueLocale = issueLocale,
16+
sellerId = sellerId,
17+
version = version
18+
};
19+
20+
}
21+
22+
23+
public void AddPriceMessage(IList<PriceMessage> messages)
24+
{
25+
int index = jsonMessagesData.messages.Count;
26+
foreach (var itm in messages)
27+
{
28+
var patcheValueData = new PatcheValueData()
29+
{
30+
currency = itm.StandardPrice.currency,
31+
our_price = new List<PriceData>()
32+
{
33+
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.StandardPrice.Value } } }
34+
},
35+
};
36+
37+
if (itm.MinimumSellerAllowedPrice != null)
38+
{
39+
patcheValueData.minimum_seller_allowed_price = new List<PriceData>()
40+
{
41+
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MinimumSellerAllowedPrice.Value } } }
42+
};
43+
}
44+
45+
if (itm.MaximumSellerAllowedPrice != null)
46+
{
47+
patcheValueData.maximum_seller_allowed_price = new List<PriceData>()
48+
{
49+
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MaximumSellerAllowedPrice.Value } } }
50+
};
51+
}
52+
53+
var msg = new MessagesData()
54+
{
55+
messageId = ++index,
56+
sku = itm.SKU,
57+
operationType = "PATCH",
58+
productType = "PRODUCT",
59+
patches = new List<PatcheData>{
60+
new PatcheData()
61+
{
62+
op = "replace",
63+
path = "/attributes/purchasable_offer",
64+
value =new List<PatcheValueData>{ patcheValueData }
65+
}
66+
}
67+
};
68+
69+
jsonMessagesData.messages.Add(msg);
70+
}
71+
}
72+
73+
public string GetJSON()
74+
{
75+
string jsonString = JsonConvert.SerializeObject(jsonMessagesData, Formatting.Indented, new JsonSerializerSettings
76+
{
77+
NullValueHandling = NullValueHandling.Ignore
78+
});
79+
80+
return jsonString;
81+
}
82+
}
83+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
2+
{
3+
public class HeaderData
4+
{
5+
public string sellerId { get; set; }
6+
public string version { get; set; }
7+
public string issueLocale { get; set; }
8+
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
4+
{
5+
public class JsonMessagesData
6+
{
7+
public HeaderData header { get; set; }
8+
public IList<MessagesData> messages { get; set; } = new List<MessagesData>();
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
4+
{
5+
public class MessagesData
6+
{
7+
public int messageId { get; set; }
8+
public string sku { get; set; }
9+
public string operationType { get; set; }
10+
public string productType { get; set; }
11+
public IList<PatcheData> patches { get; set; }
12+
//public IList<attributes> attributes { get; set; }
13+
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
4+
{
5+
public class PatcheData
6+
{
7+
public string op { get; set; }
8+
public string path { get; set; }
9+
public IList<PatcheValueData> value { get; set; }
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
3+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
4+
{
5+
public class PatcheValueData
6+
{
7+
public string value { get; set; }
8+
public string language_tag { get; set; }
9+
public string marketplace_id { get; set; }
10+
public string fulfillment_channel_code { get; set; }
11+
public int? quantity { get; set; }
12+
public int? lead_time_to_ship_max_days { get; set; }
13+
public string currency { get; set; }
14+
public IList<PriceData> our_price { get; set; }
15+
public IList<PriceData> minimum_seller_allowed_price { get; set; }
16+
public IList<PriceData> maximum_seller_allowed_price { get; set; }
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
3+
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
4+
{
5+
public class PriceData
6+
{
7+
public IList<SchedulePriceData> schedule { get; set; }
8+
}
9+
public class SchedulePriceData
10+
{
11+
public decimal value_with_tax { get; set; }
12+
}
13+
}

Source/FikaAmazonAPI/ConstructFeed/Messages/StandardPrice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace FikaAmazonAPI.ConstructFeed.Messages
55
public class StandardPrice
66
{
77
[XmlText]
8-
public string Value { get; set; }
8+
public decimal Value { get; set; }
99
[XmlAttribute]
1010
public string currency { get; set; }
1111
}

Source/FikaAmazonAPI/FikaAmazonAPI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<Product>CSharp Amazon Sp API</Product>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<LangVersion>8.0</LangVersion>
10-
<Version>1.7.35</Version>
11-
<AssemblyVersion>1.7.35</AssemblyVersion>
12-
<FileVersion>1.7.35</FileVersion>
10+
<Version>1.7.36</Version>
11+
<AssemblyVersion>1.7.36</AssemblyVersion>
12+
<FileVersion>1.7.36</FileVersion>
1313
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1414
<PackageProjectUrl>https://github.com/abuzuhri/Amazon-SP-API-CSharp</PackageProjectUrl>
1515
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)