-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using FikaAmazonAPI.ConstructFeed.JsonMessages; | ||
using FikaAmazonAPI.ConstructFeed.Messages; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed | ||
{ | ||
public class ConstructJSONFeedService | ||
{ | ||
JsonMessagesData jsonMessagesData = new JsonMessagesData(); | ||
public ConstructJSONFeedService(string sellerId, string version = "2.0", string issueLocale = "en_US") | ||
{ | ||
jsonMessagesData.header = new HeaderData() | ||
{ | ||
issueLocale = issueLocale, | ||
sellerId = sellerId, | ||
version = version | ||
}; | ||
|
||
} | ||
|
||
|
||
public void AddPriceMessage(IList<PriceMessage> messages) | ||
{ | ||
int index = jsonMessagesData.messages.Count; | ||
foreach (var itm in messages) | ||
{ | ||
var patcheValueData = new PatcheValueData() | ||
{ | ||
currency = itm.StandardPrice.currency, | ||
our_price = new List<PriceData>() | ||
{ | ||
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.StandardPrice.Value } } } | ||
}, | ||
}; | ||
|
||
if (itm.MinimumSellerAllowedPrice != null) | ||
{ | ||
patcheValueData.minimum_seller_allowed_price = new List<PriceData>() | ||
{ | ||
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MinimumSellerAllowedPrice.Value } } } | ||
}; | ||
} | ||
|
||
if (itm.MaximumSellerAllowedPrice != null) | ||
{ | ||
patcheValueData.maximum_seller_allowed_price = new List<PriceData>() | ||
{ | ||
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MaximumSellerAllowedPrice.Value } } } | ||
}; | ||
} | ||
|
||
var msg = new MessagesData() | ||
{ | ||
messageId = ++index, | ||
sku = itm.SKU, | ||
operationType = "PATCH", | ||
productType = "PRODUCT", | ||
patches = new List<PatcheData>{ | ||
new PatcheData() | ||
{ | ||
op = "replace", | ||
path = "/attributes/purchasable_offer", | ||
value =new List<PatcheValueData>{ patcheValueData } | ||
} | ||
} | ||
}; | ||
|
||
jsonMessagesData.messages.Add(msg); | ||
} | ||
} | ||
|
||
public string GetJSON() | ||
{ | ||
string jsonString = JsonConvert.SerializeObject(jsonMessagesData, Formatting.Indented, new JsonSerializerSettings | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}); | ||
|
||
return jsonString; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class HeaderData | ||
{ | ||
public string sellerId { get; set; } | ||
public string version { get; set; } | ||
public string issueLocale { get; set; } | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/JsonMessagesData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class JsonMessagesData | ||
{ | ||
public HeaderData header { get; set; } | ||
public IList<MessagesData> messages { get; set; } = new List<MessagesData>(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class MessagesData | ||
{ | ||
public int messageId { get; set; } | ||
public string sku { get; set; } | ||
public string operationType { get; set; } | ||
public string productType { get; set; } | ||
public IList<PatcheData> patches { get; set; } | ||
//public IList<attributes> attributes { get; set; } | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class PatcheData | ||
{ | ||
public string op { get; set; } | ||
public string path { get; set; } | ||
public IList<PatcheValueData> value { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class PatcheValueData | ||
{ | ||
public string value { get; set; } | ||
public string language_tag { get; set; } | ||
public string marketplace_id { get; set; } | ||
public string fulfillment_channel_code { get; set; } | ||
public int? quantity { get; set; } | ||
public int? lead_time_to_ship_max_days { get; set; } | ||
public string currency { get; set; } | ||
public IList<PriceData> our_price { get; set; } | ||
public IList<PriceData> minimum_seller_allowed_price { get; set; } | ||
public IList<PriceData> maximum_seller_allowed_price { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FikaAmazonAPI.ConstructFeed.JsonMessages | ||
{ | ||
public class PriceData | ||
{ | ||
public IList<SchedulePriceData> schedule { get; set; } | ||
} | ||
public class SchedulePriceData | ||
{ | ||
public decimal value_with_tax { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters